[fix] Add missing bounds checks during compression #2709
Merged
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.
passes an erroneously large size to
ZSTD_entropyCompressSeqStore()
, whichcan then write the compressed data past the end of the buffer. This is a new
regression in v1.5.0 when the block splitter is enabled. It is either enabled
explicitly, or implicitly when using the optimal parser and
ZSTD_compress2()
or
ZSTD_compressStream*()
.HUF_writeCTable_wksp()
omits a bounds check when callingHUF_compressWeights()
. If it is called withdstCapacity == 0
it will passan erroneously large size to
HUF_compressWeights()
, which can then writepast the end of the buffer. This bug has been present for ages. However, I
believe that zstd cannot trigger the bug, because it never calls
HUF_compress*()
withdstCapacity == 0
because of this check.Credit to: Oss-Fuzz