fix: patch Huffman OOB read and optimize encoders#11
Merged
Conversation
…ze encoders Security fix: - Fix out-of-bounds read in Huffman decode table build: when a corrupt or single-child tree caused cur < 0, the `e.next = cur` assignment at loop exit overwrote the earlier `e.next = root` safety reset, producing a negative node index. On crafted input with a single-symbol frequency table (e.g. empty input), this led to `table[-1]` access (undefined behavior). Now guarded with a `corrupt` flag so the root reset survives. Optimization: - Eliminate O(n) payload copy in arithmetic decode: BitReader now accepts (const uint8_t*, size_t) in addition to const vector&, letting the decoder read directly from the input buffer at the payload offset without allocating a temporary vector. - Add Vec::reserve() to arithmetic and RLE encoders to reduce reallocation overhead (matching huffman/range encoders). Test coverage: - Add all_same_byte.bin corpus file (4096 zero bytes) to exercise RLE single-run and Huffman single-symbol edge cases, included in the CLI smoke test default corpus. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Test plan
Generated with Devin