Repository navigation
fix(cpp): reject corrupt dictionary pages with negative entry count - #1157
Merged
Merged
Conversation
DictionaryDecoder::read_string ignored init_map()'s return value and indexed entry_index_ with an unchecked code. A DICTIONARY-encoded page whose entry count decodes to a negative var-int leaves entry_index_ empty, so the following entry_index_[code] read is out of bounds and crashes with SIGSEGV. Validate the entry count and the decoded code index, and propagate the init_map() error so a corrupt page returns E_TSFILE_CORRUPTED instead of crashing.
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
A DICTIONARY-encoded string page stores its entry count as a var-int.
DictionaryDecoder::read_stringignored the return value ofinit_map()and then indexed
entry_index_with the decoded code without boundschecking.
A page whose entry count decodes to a negative value (e.g. -1) leaves
entry_index_empty, so the subsequententry_index_[code]read is out ofbounds and crashes the process (SIGSEGV).
Changes
init_map()returnsE_TSFILE_CORRUPTEDwhen the entry count isnegative.
read_string()now checks theinit_map()and value-decoder returncodes and bounds-checks the code index, returning
E_TSFILE_CORRUPTEDon a corrupt page.
asserts
E_TSFILE_CORRUPTED(previously this crashed).Testing
DictionaryDecoderCorruptionTest.NegativeEntryCountReturnsCorruptedpasses.
EncodingCoveragepass.