validate utf-8 continuation bytes in utf8ToCodepoint - #1702
Open
SABITHSAHEB wants to merge 3 commits into
Open
Conversation
Contributor
Author
|
any update? |
Contributor
|
| Filename | Overview |
|---|---|
| src/lib_json/json_writer.cpp | Validates continuation bytes, preserves the first offending byte for subsequent decoding, and rejects code points above U+10FFFF. |
| src/test_lib_json/main.cpp | Adds regression tests covering malformed prefixes, preserved ASCII suffixes, out-of-range code points, and valid multibyte input. |
Reviews (2): Last reviewed commit: "consume the valid continuation prefix of..." | Re-trigger Greptile
Coverage Report for CI Build 32591467250Coverage increased (+0.03%) to 89.935%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
When a multibyte sequence has valid continuation bytes followed by a non-continuation byte, leave the decoder on the last valid trailing byte so the whole malformed prefix is replaced by a single U+FFFD instead of one per byte. "\xE2\x82A" now serializes as "\ufffdA".
Contributor
Author
|
@baylesj addressed the one item from the review above (valid continuation prefix was being replaced byte by byte). The truncated-at-end-of-input case goes through the pre-existing length checks, so I left that path alone. |
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.
Validate each trailing byte and cap at U+10FFFF, returning U+FFFD without advancing past bytes that are not part of the sequence. This is the lenient replacement behaviour rather than a hard error, so valid UTF-8 output is unchanged.