oven-sh/bun · error

convert_utf8_to_utf16_in_buffer: buf too small (have {} u16

Error message

convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)

What it means

Error "convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)" thrown in oven-sh/bun.

Source

Thrown at src/bun_core/string/immutable.rs:2448

        let c = s[0].into();
        (c >= u32::from(b'a') && c <= u32::from(b'z'))
            || (c >= u32::from(b'A') && c <= u32::from(b'Z'))
    }
}

/// `strings.convertUTF8toUTF16InBuffer` — UTF-8 → UTF-16LE into a caller-supplied
/// buffer (capacity ≥ `input.len()` u16). SIMD fast path via simdutf; on invalid
/// UTF-8 falls back to a scalar WTF-8 decoder that emits U+FFFD for malformed
/// bytes and passes unpaired surrogates through (so non-empty input never yields
/// an empty slice — fixes #8197).
///
/// Panics when the output does not fit. Callers that cannot statically size
/// `buf` for the worst case must use [`try_convert_utf8_to_utf16_in_buffer`].
pub fn convert_utf8_to_utf16_in_buffer<'a>(buf: &'a mut [u16], input: &[u8]) -> &'a mut [u16] {
    let buf_len = buf.len();
    match try_convert_utf8_to_utf16_in_buffer(buf, input) {
        Some(out) => out,
        None => panic!(
            "convert_utf8_to_utf16_in_buffer: buf too small (have {} u16 for {} input bytes)",
            buf_len,
            input.len(),
        ),
    }
}

/// Checked variant of [`convert_utf8_to_utf16_in_buffer`]: returns `None` when
/// the converted output does not fit in `buf`, and never writes past `buf`.
///
/// simdutf's convert API takes only an output *pointer* and writes however
/// many units the input needs, so it must not be entered unless the output
/// provably fits: either `input.len() <= buf.len()` (a UTF-16 unit always
/// consumes at least one UTF-8 byte, and surrogate pairs produce 2 units from
/// 4 bytes), or the exact converted length fits. On invalid input simdutf
/// stops at the first error having written only the valid prefix's units,
/// which is ≤ that same exact-length estimate; the WTF-8 fallback can exceed
/// the estimate (stray continuation bytes become one U+FFFD each), so it

View on GitHub (pinned to 8c5296ac45)

When it happens

Trigger: Thrown at src/bun_core/string/immutable.rs:2448 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/ee96d8203533b3da. Report an issue: GitHub.