From: Dean Chen <862469039@qq.com> Date: Sun, 15 Nov 2026 01:19:24 +0000 (+0500) Subject: Parser: fix overlong code point escape conversion X-Git-Url: https://git.kaiwu.me/ngx_http_fastcgi_module.html?a=commitdiff_plain;h=8edb36aa0979c54e57d033cd73dc10dab6f98713;p=njs.git 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. --- diff --git a/src/njs_parser.c b/src/njs_parser.c index 0fd63bbb..53c132d4 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -8878,7 +8878,7 @@ njs_parser_escape_string_calc_length(njs_parser_t *parser, src++; hex_length = 0; - hex_end = end; + hex_end = (end - src > 7) ? src + 7 : end; goto hex; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index acbcfb6e..be382b3e 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -8696,6 +8696,12 @@ static njs_unit_test_t njs_test[] = { njs_str("'\\u{a00000}'"), njs_str("SyntaxError: Invalid Unicode code point \"\\u{a00000}\"") }, + { njs_str("'\\u{11111111111111110}'"), + njs_str("SyntaxError: Invalid Unicode code point \"\\u{11111111111111110}\"") }, + + { njs_str("`\\u{11111111111111110`"), + njs_str("SyntaxError: Invalid Unicode code point \"\\u{11111111111111110\"") }, + { njs_str("'\\x61'"), njs_str("a") },