Skip to content

reject invalid hex digits in \u escapes - #1105

Open
nabhan06 wants to merge 1 commit into
DaveGamble:masterfrom
nabhan06:reject-invalid-unicode-escape
Open

nabhan06 wants to merge 1 commit into
DaveGamble:masterfrom
nabhan06:reject-invalid-unicode-escape

Conversation

@nabhan06

Copy link
Copy Markdown

parse_hex4 returns 0 when it hits a non-hex digit, and utf16_literal_to_utf8 cannot tell that apart from a literal \u0000, so any malformed escape like \uX000 or \u00G1 is accepted and decoded as U+0000. Since valuestring is NUL-terminated the value is silently cut off there: {"role":"admin\uZZZZ-guest"} parses fine with role set to "admin", while conforming parsers reject the document. parse_hex4 now reports the failure separately from the value and both halves of a surrogate pair are checked; tests for the invalid cases are added to parse_hex4.c and parse_string.c (the existing parse_hex4 tests are adjusted for the new signature).

Fixes #635

parse_hex4 returned 0 for a non-hex digit, so utf16_literal_to_utf8
decoded a malformed escape such as \uX000 as U+0000 and the string was
silently truncated there. Report the failure separately and reject the
escape.

Fixes DaveGamble#635
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid \uXXXX not detected

1 participant