mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
The ICU unit's WTF-8 to UTF-16 conversion counted units from lead bytes alone. A 4-byte-shaped encoding of a BMP value counted two units and wrote one, so ICU received a length past the units written, and word segments built from those ranges could return prior heap contents. The conversion now decodes each maximal ill-formed subsequence to U+FFFD, as the WHATWG UTF-8 decoder does, keeps WTF-8's 3-byte lone surrogates as their unit, and reports the units it wrote. The decoder lives in scr_intl_utf16.h. Directory entry names (readdir, opendir) and process.argv entries now decode as UTF-8 with U+FFFD for malformed bytes, as Node decodes them, instead of entering strings as raw bytes. test_intl_utf16.c checks the decoder against Node's TextDecoder over malformed sequences. intl-malformed-utf8.test.ts compares a program that segments malformed directory names and an argument against Node.