reject out-of-range code points in UTF-32 wide-string input - #5348
Open
Angadi56 wants to merge 2 commits into
Open
reject out-of-range code points in UTF-32 wide-string input#5348Angadi56 wants to merge 2 commits into
Angadi56 wants to merge 2 commits into
Conversation
nlohmann
requested changes
Aug 3, 2026
nlohmann
left a comment
Owner
There was a problem hiding this comment.
Good catch! The change looks good, but please fix the self-cast warning from GCC.
Owner
|
Clang was updated and the latest develop branch fixes a CI issue. Please rebase to the latest develop branch. |
Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com>
Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com>
Angadi56
force-pushed
the
utf32-eof-sentinel
branch
from
August 4, 2026 18:11
7647568 to
0b552a4
Compare
Contributor
Author
|
Done. Rebased onto the latest develop and dropped the cast in the out-of-range branch. char_traits::int_type is int and 0xFF already is one, so the plain assignment avoids the useless-cast warning. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wide_string_input_helper<BaseInputAdapter, 4>::fill_bufferconverts UTF-32 input into the UTF-8 the lexer reads, and any code point above U+10FFFF falls into an "unknown character" branch that passes the code unit straight through. That pass-through narrows a 32-bit unit toint, so the single unit0xFFFFFFFFarrives as-1, which is exactlystd::char_traits<char>::eof(). The lexer reads that as end of input, so the parse stops there and the strict trailing check inparser::parsestill succeeds:json::parse(std::u32string(U"[1]") + char32_t(0xFFFFFFFF) + U"anything")returns[1]andjson::acceptreturnstrue, with every unit after the sentinel silently discarded. I found it while lining this branch up against the sibling UTF-16 helper, whose pass-through is safe only because its units cannot exceed0xFFFF. The neighboring out-of-range values already behave correctly, since0x110000and a lone surrogate both stay positive after the cast and raiseparse_error.101, so only the one value that collides with the sentinel is mis-decoded. The fix has that branch emit a byte that is never valid UTF-8 instead of a narrowed unit, which is the same collisioninput_stream_adapter::get_characteralready documents guarding against, and it leaves the two in-range casts in the file alone because they are bounded to0..0x7F. Valid input is unchanged and the regression test goes in the existing invalidstd::u32stringsection.make amalgamate.