fix(fsst): grow decode buffer to prevent out-of-bounds write#7267
Open
Noethix55555 wants to merge 1 commit into
Open
fix(fsst): grow decode buffer to prevent out-of-bounds write#7267Noethix55555 wants to merge 1 commit into
Noethix55555 wants to merge 1 commit into
Conversation
decompress only required a 3x output buffer, but an FSST code byte can expand to an 8-byte symbol and the decode loop writes 8 bytes at a time through raw pointers. On data that compresses better than 3:1, honoring the documented minimum overran the buffer (a heap out-of-bounds write, observed as a segfault). Size the output buffer for the worst case before decoding; it is shrunk to the real length afterwards. Adds a regression test.
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
fsst::fsst::decompressonly required a3 * inputoutput buffer, but an FSST code byte can decode to an 8-byte symbol and the decode loop writes 8 bytes at a time through raw pointers. On data that compresses better than 3:1, honoring the documented minimum overran the buffer (a heap out-of-bounds write, observed as a segfault).This sizes the output buffer for the worst case before decoding, then shrinks it to the real length at the end. The change is internal to the decode path and does not change results for callers that already pass a large enough buffer (in-tree callers pass
8 * input).Closes #7266. Related: #2606.
Test
Added
rust/compression/fsst/tests/buffer_bound.rs: it compresses an ~8:1 input and decompresses into the documented 3x buffer. This segfaulted before the change and round-trips correctly after.cargo test -p fsstandcargo clippy -p fsst --testspass.