Skip to content

fix(cpp): reject corrupt dictionary pages with negative entry count - #1157

Merged
ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:fix-197-dict-neg-len
Nov 27, 2026
Merged

ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:fix-197-dict-neg-len

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

A DICTIONARY-encoded string page stores its entry count as a var-int.
DictionaryDecoder::read_string ignored the return value of init_map()
and then indexed entry_index_ with the decoded code without bounds
checking.

A page whose entry count decodes to a negative value (e.g. -1) leaves
entry_index_ empty, so the subsequent entry_index_[code] read is out of
bounds and crashes the process (SIGSEGV).

Changes

  • init_map() returns E_TSFILE_CORRUPTED when the entry count is
    negative.
  • read_string() now checks the init_map() and value-decoder return
    codes and bounds-checks the code index, returning E_TSFILE_CORRUPTED
    on a corrupt page.
  • Added a regression test that decodes a page with a -1 entry count and
    asserts E_TSFILE_CORRUPTED (previously this crashed).

Testing

  • New DictionaryDecoderCorruptionTest.NegativeEntryCountReturnsCorrupted
    passes.
  • All existing dictionary decoder tests and EncodingCoverage pass.

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.
@ColinLeeo
ColinLeeo merged commit 051cb0c into apache:develop Nov 27, 2026
49 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.

1 participant