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++;
hex_length = 0;
- hex_end = end;
+ hex_end = (end - src > 7) ? src + 7 : end;
goto hex;
{ 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") },