fix: bounds check prefixes index in convert_to_unicode#289
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
After setting index from enc->bytemap[], validate that it is less than enc->prefixes_size before using it to access enc->prefixes[] on the next loop iteration. A corrupt or malicious .enc file could contain a bytemap entry pointing beyond the prefixes array, causing an out-of-bounds read. The fix mirrors the validation pattern already used during loading in XML_LoadEncoding and safely breaks out of the conversion loop when an invalid index is encountered (returning -1 for unmappable character). Adds test exercising the code path with a crafted encoding file whose bytemap contains an index beyond prefixes_size. Fixes #284 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #289 +/- ##
==========================================
+ Coverage 76.40% 76.68% +0.27%
==========================================
Files 1 1
Lines 1102 1115 +13
Branches 346 352 +6
==========================================
+ Hits 842 855 +13
+ Misses 52 51 -1
- Partials 208 209 +1
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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.
Summary
Adds a missing bounds check in
convert_to_unicode()where theindexvariable (set fromenc->bytemap[]) is used to accessenc->prefixes[index]without validating thatindex < enc->prefixes_size. A corrupt or malicious.encfile could trigger an out-of-bounds read.Fixes #284
Changes
if (index >= enc->prefixes_size) break;after bytemap lookup inconvert_to_unicode()(Expat/Expat.xs:1145)Test plan
make testpasses (728 tests, all successful)prefixes_sizeconvert_to_unicodesafely returns -1Generated by Kōan /fix
Quality Report
Changes: 2 files changed, 84 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline