Repository navigation
fix: reject invalid dictionaries and support aliased decode buffers - #12
Merged
ChillerDragon merged 1 commit intoAug 20, 2026
Merged
Conversation
Member
|
Thanks |
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.
Follow-up review of current
master(d21ea85) after #11.Findings fixed
Invalid dictionaries
Dictionaryis an exported type, so callers can construct its zero value or passniltoNewHuffmanDict,NewReaderDict,NewWriterDict,CompressDict, andDecompressDict.CompressandWriter.Writereport success while emitting no frame, causing silent data loss.All encode/decode entry points now reject nil or uninitialized dictionaries through the existing
ErrHuffmanCompress/ErrHuffmanDecompresschains. Nil codec, Reader, and Writer receivers also return defined errors instead of panicking. A copied, constructor-built dictionary remains valid.Overlapping DecompressTo buffers
DecompressTohas append-style semantics, but an output slice whose writable capacity overlappeddatacould overwrite compressed bytes before they were consumed. High-expansion inputs such as long zero runs reliably turned this into truncation errors or corrupted decoding.The decoder now detects overlap between the writable destination range and compressed input and preserves the source only in that exceptional case. Separate reused buffers retain their zero-allocation path. The overlap helper only compares addresses, never converts integers back to pointers, and uses subtraction so the arithmetic is safe on 32-bit platforms.
Compatibility and security impact
Verification
go test ./... -count=1go test -race ./... -count=1go test -gcflags=all=-d=checkptr=2 ./... -count=1go vet ./...staticcheck ./...govulncheck ./...: no vulnerabilities foundupstream/master: no statistically significant individual changes, +0.37% full-suite geomean, identical allocations