{{ message }}
Repository navigation
ICU-23531 Validate RBBI state table row fields and section offsets - #4257
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
Row fields read from compiled break rule data index run time arrays: RuleBasedBreakIterator::handleNext() writes fLookAheadMatches at the index taken from a row's look-ahead field, and reads next-state values and rule status entries the same way. None of these were checked against the sizes declared in the data, so a crafted rule blob opened with ubrk_openBinaryRules() caused a heap out of bounds write while iterating text. Check the section offsets and lengths against the total data length before use, and check every row of both state tables: look-ahead slots and accepting values must fit the look-ahead results array, tag indexes must fit the rule status table including the counted entries, next state values must address rows of their own table, and trie values must be below the category count. Malformed data now fails with U_INVALID_FORMAT_ERROR.
Author
This branch has not been deployed
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.

Description
ICU-23531 reports a heap out of bounds write reachable from
ubrk_openBinaryRules()when the compiled break rule blob contains crafted state table rows. This change validates the row fields and section offsets of rule data when it is loaded, so malformed data is rejected withU_INVALID_FORMAT_ERRORinstead of being executed.The unvalidated values, all read straight from the data blob:
RuleBasedBreakIterator::handleNext()writesfLookAheadMatches[row->fLookAhead]. The array is allocated withfLookAheadResultsSizeentries from the same blob, and the only existing check is aU_ASSERT, which compiles away in release builds.handleNext()also readsfLookAheadMatches[row->fAccepting],row->fNextState[category](wherecategorycomes from the trie and is only asserted belowfCatCount), andfRuleStatusTable[row->fTagsIdx]and the counted entries that follow it.fFTable,fRTable,fTrie,fRuleSource,fStatusTable) are used as pointer offsets without checking that the section stays inside the buffer.Reproducer, run against a build with address sanitizer, using rules compiled by ICU itself with one look-ahead slot rewritten from its real value to 200 while
fLookAheadResultsSizeis 3:After this change the same program prints
openBinaryRules: U_INVALID_FORMAT_ERRORand exits cleanly.What the new validation checks in
RBBIDataWrapper::init():fLength, checked in 64 bit arithmetic.ACCEPTING_UNCONDITIONALmust be belowfLookAheadResultsSize; a tag index must be inside the rule status table including its counted entries; every next-state value must address a row of its own table.fCatCount.The checks are permissive where the format allows it, for example section sizes are 8 byte aligned by the rule builder, so any padding remains valid.
Note: this complements the header offset checking in PR #3961, which covers the same init function from the init time out of bounds read half of ICU-23531. The row field validation and the trie value check here cover the run time write half; either PR is self sufficient.
Testing
RBBIAPITest/TestBinaryRuleRowFieldValidationwas added. It compiles rules containing a look-ahead, takes them apart as a binary blob, and reopens the blob after corrupting, one at a time, a look-ahead slot, a next-state value, a tag index, and the trie section offset. Each variant must fail withU_INVALID_FORMAT_ERROR.intltest rbbipasses in full with this change, so all shipped break iterator data still loads.cintltstalso passes.ICU-23531
Checklist