fix: off-by-one heap buffer overread in seekable format - #4758
fix: off-by-one heap buffer overread in seekable format#4758VirajMishra1 wants to merge 2 commits into
Conversation
ZSTD_seekTable_getFrameDecompressedSize uses > instead of >= for the frameIndex bounds check, unlike its sister function ZSTD_seekTable_getFrameCompressedSize which correctly uses >=. When frameIndex == tableLen, the function accesses entries[tableLen + 1], reading past the allocated array (numFrames + 1 entries, valid indices 0..numFrames). This is a heap buffer overread. Fix: change > to >= to match getFrameCompressedSize.
Add --stream-size flag to pzstd, matching the existing flag in the main zstd CLI. When compressing from stdin/pipe, this tells the compressor the total input size, enabling it to write the content size in the frame header and optimize window size for better compression ratios. Closes facebook#3171 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Hi @VirajMishra1! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
ZSTD_seekTable_getFrameDecompressedSizeincontrib/seekable_format/zstdseek_decompress.cuses>instead of>=for theframeIndexbounds check (line 369), unlike its sister functionZSTD_seekTable_getFrameCompressedSizewhich correctly uses>=(line 357).When
frameIndex == tableLen, the function does not return an error and proceeds to accessentries[frameIndex + 1]. The seek table allocatesnumFrames + 1entries, so valid indices are0..numFrames. IndexnumFrames + 1is a heap buffer overread of uninitialized memory.Any application iterating with
for (i = 0; i <= numFrames; i++)and callinggetFrameDecompressedSizewill silently read past the array. The compressed-size variant catches this; the decompressed-size variant does not.Fix: change
>to>=on line 369, matchinggetFrameCompressedSize.Test: added Test 6 in
contrib/seekable_format/tests/seekable_tests.casserting both functions return errors forframeIndex == nbFrames. All 6 tests pass.