Skip to content

Reject malformed UTF-8 sequences in read_ut8_sequence - #1169

Merged
tgregg merged 1 commit into
amazon-ion:masterfrom
radhika1314:utf8-sequence-validation
Dec 3, 2026
Merged

tgregg merged 1 commit into
amazon-ion:masterfrom
radhika1314:utf8-sequence-validation

Conversation

@radhika1314

Copy link
Copy Markdown
Contributor

Issue #, if available: N/A

Description of changes:

read_ut8_sequence assembles a multi-byte sequence without checking that the bytes after the lead byte are continuation bytes, and without rejecting non-shortest forms, so a truncated lead byte inside a quoted string or symbol consumes whatever comes next, including the closing quote: ["\xC3"x","c"] reads as a two element list rather than being rejected. An overlong form decodes to the character it encodes, so {path:"..\xE0\x80\xAF.."} reads as {path:"../.."} with no 0x2F byte anywhere in the input, which means a byte level check and the parser can disagree about the same document. The binary reader already rejects both of these in its CharsetDecoder, so this validates each continuation byte and bounds the decoded scalar by the sequence length to match it.

Two notes on the diff: the expected message in IonExceptionTest.testCauseOfWrongEncoding changed because that input ('1\xF5111') now fails on the bad continuation byte instead of later on the out of range scalar, and spotlessApply rewrote that file's license header on the way through. UTF-8 encoded surrogate pairs are left alone since testSurrogateGluing covers them deliberately.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@radhika1314

Copy link
Copy Markdown
Contributor Author

any update?

@tgregg
tgregg force-pushed the utf8-sequence-validation branch from 1c9313c to 9691d34 Compare December 2, 2026 23:25
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.22222% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.37%. Comparing base (3c1b6b1) to head (9691d34).
⚠️ Report is 171 commits behind head on master.

Files with missing lines Patch % Lines
...a/com/amazon/ion/impl/IonReaderTextRawTokensX.java 72.22% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1169      +/-   ##
============================================
+ Coverage     67.23%   68.37%   +1.14%     
- Complexity     5484     5744     +260     
============================================
  Files           159      160       +1     
  Lines         23025    23509     +484     
  Branches       4126     4238     +112     
============================================
+ Hits          15481    16075     +594     
+ Misses         6262     6133     -129     
- Partials       1282     1301      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tgregg tgregg 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, thanks for the contribution!

@tgregg
tgregg merged commit 65e0363 into amazon-ion:master Dec 3, 2026
31 of 38 checks passed
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.

2 participants