Skip to content

MINOR: [c++] reject lone low surrogate U+DFFF in JSON decoder#3841

Open
arib06 wants to merge 1 commit into
apache:mainfrom
arib06:cpp-json-lone-low-surrogate
Open

MINOR: [c++] reject lone low surrogate U+DFFF in JSON decoder#3841
arib06 wants to merge 1 commit into
apache:mainfrom
arib06:cpp-json-lone-low-surrogate

Conversation

@arib06

@arib06 arib06 commented Jul 9, 2026

Copy link
Copy Markdown

What is the purpose of the change

JsonParser::decodeString rejects unpaired low surrogates, but the range check uses an exclusive upper bound (n >= 0xdc00 && n < 0xdfff), so the last low surrogate U+DFFF is not caught. It falls through and is emitted as the 3-byte sequence ED BF BF, which is not valid UTF-8 (it encodes a surrogate half). Every other lone low surrogate (U+DC00..U+DFFE) is already rejected. The trailing-surrogate check a few lines above already treats U+DFFF as a valid low surrogate (m > 0xdfff), so the lone-surrogate branch is off by one. This makes the bound inclusive so U+DFFF is rejected consistently.

Verifying this change

This change added tests and can be verified as follows:

  • Added a JSON decoder test asserting that a lone low surrogate, including \udfff, is rejected. It fails on the current code (U+DFFF is accepted) and passes with the fix.

Documentation

  • Does this pull request introduce a new feature? no

The lone-surrogate check used an exclusive upper bound (n < 0xdfff), so the last low surrogate U+DFFF slipped through and was emitted as the invalid UTF-8 sequence ED BF BF; make the bound inclusive to match the trailing-surrogate validation in the same function.
@github-actions github-actions Bot added the C++ Pull Requests for C++ binding label Jul 9, 2026

@thiru-mg thiru-mg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I can merge if there are no objection from others.

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

Labels

C++ Pull Requests for C++ binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants