Fall back to level-1 compressor for unsupported compression levels - #255
Open
rootkiller6788 wants to merge 1 commit into
Open
Fall back to level-1 compressor for unsupported compression levels#255rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
CompressionOptions accepts any compression level, but InternalCompress only handles levels 1 and 2. For any other level the `end` pointer was left nullptr, so `end - dest` was undefined behaviour and the resulting write length was garbage, which crashed or corrupted the compressed output. Treat every unsupported level as level 1 instead, and add a regression test that verifies unsupported levels produce the level-1 output and round-trip correctly.
rootkiller6788
marked this pull request as ready for review
August 26, 2026 15:10
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.
What
CompressionOptionsis constructible with anyintcompression level, andsnappy.ccdocuments levels 3+ as "currently not supported" rather than rejecting them. InInternalCompress, the level dispatch only setendfor levels 1 and 2; for any other levelendstayednullptr, andwriter->Append(dest, end - dest)then computed a garbage length from undefined behaviour. The string-basedCompress()path would throwstd::out_of_rangefromstd::string::erase, and the raw path wrote through a wild pointer.This only manifests with levels outside
[1, 2], so the fuzzers (which iterate levels 1..2) never hit it.Fix
Treat every level other than 2 as the default (level 1) compressor instead of leaving
enduninitialized. The existingassert(options.level == 1 || options.level == 2)was relaxed toassert(options.level >= 1)to match the new tolerant dispatch.Test
Added
Snappy.UnsupportedCompressionLevels, which compresses with levels 3..9, asserts the output matches the level-1 baseline, and round-trips throughUncompress. Full suite passes in Debug and Release (25/25).