]> git.kaiwu.me - njs.git/commit
Parser: fix overlong code point escape conversion
authorDean Chen <862469039@qq.com>
Sun, 15 Nov 2026 01:19:24 +0000 (06:19 +0500)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 16 Nov 2026 01:23:35 +0000 (17:23 -0800)
commit8edb36aa0979c54e57d033cd73dc10dab6f98713
tree66245b78a0f69b72fe60d7c69b319fda5931402d
parent2786bd98a5363849f5641b624469251800e677f0
Parser: fix overlong code point escape conversion

Previously, when computing the length of an escaped string, all hex
digits of a "\u{...}" escape were accumulated into a double and
converted to uint64_t before the existing six-digit limit was checked.
For overlong escapes, the parsed value could be outside the range of
uint64_t, including due to rounding with 16 digits.  The conversion is
undefined behavior and aborts builds with UBSan enabled.

Now at most seven digits are parsed, which still rejects longer escapes
with the same SyntaxError while keeping the value in range.

The issue was introduced in 7cff11dc ("Fixed large non-decimal literals."),
which changed njs_number_hex_parse() to return a double.

This closes #1158 issue on GitHub.
src/njs_parser.c
src/test/njs_unit_test.c