{"record":{"id":"ee96d8203533b3da","repo":"oven-sh/bun","slug":"convert-utf8-to-utf16-in-buffer-buf-too-small-ha","errorCode":null,"errorMessage":"convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)","messagePattern":"convert_utf8_to_utf16_in_buffer: buf too small \\(have (.+?) u16 for (.+?) input bytes\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bun_core/string/immutable.rs","lineNumber":2448,"sourceCode":"        let c = s[0].into();\n        (c >= u32::from(b'a') && c <= u32::from(b'z'))\n            || (c >= u32::from(b'A') && c <= u32::from(b'Z'))\n    }\n}\n\n/// `strings.convertUTF8toUTF16InBuffer` — UTF-8 → UTF-16LE into a caller-supplied\n/// buffer (capacity ≥ `input.len()` u16). SIMD fast path via simdutf; on invalid\n/// UTF-8 falls back to a scalar WTF-8 decoder that emits U+FFFD for malformed\n/// bytes and passes unpaired surrogates through (so non-empty input never yields\n/// an empty slice — fixes #8197).\n///\n/// Panics when the output does not fit. Callers that cannot statically size\n/// `buf` for the worst case must use [`try_convert_utf8_to_utf16_in_buffer`].\npub fn convert_utf8_to_utf16_in_buffer<'a>(buf: &'a mut [u16], input: &[u8]) -> &'a mut [u16] {\n    let buf_len = buf.len();\n    match try_convert_utf8_to_utf16_in_buffer(buf, input) {\n        Some(out) => out,\n        None => panic!(\n            \"convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)\",\n            buf_len,\n            input.len(),\n        ),\n    }\n}\n\n/// Checked variant of [`convert_utf8_to_utf16_in_buffer`]: returns `None` when\n/// the converted output does not fit in `buf`, and never writes past `buf`.\n///\n/// simdutf's convert API takes only an output *pointer* and writes however\n/// many units the input needs, so it must not be entered unless the output\n/// provably fits: either `input.len() <= buf.len()` (a UTF-16 unit always\n/// consumes at least one UTF-8 byte, and surrogate pairs produce 2 units from\n/// 4 bytes), or the exact converted length fits. On invalid input simdutf\n/// stops at the first error having written only the valid prefix's units,\n/// which is ≤ that same exact-length estimate; the WTF-8 fallback can exceed\n/// the estimate (stray continuation bytes become one U+FFFD each), so it","sourceCodeStart":2430,"sourceCodeEnd":2466,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/bun_core/string/immutable.rs#L2430-L2466","documentation":"Error \"convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)\" thrown in oven-sh/bun.","triggerScenarios":"Thrown at src/bun_core/string/immutable.rs:2448 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}