Repository navigation
Don't report a truncated zstd frame when the output fills exactly - #8598
2 commits merged into
Conversation
There was a problem hiding this comment.
Superseded by the review of
f2c20c21.
This review, of 1f9c301d
✅ Approved — The fix to frame-in-progress tracking in ZstdDecoderContext::work() is correct and has a regression test. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The new frame-state logic is correct: a return value of 0 ends the frame, a call that reads input marks it in progress, and a call that reads nothing leaves the state unchanged. The regression test covers the buffer-boundary sizes.
📝 Documentation: ✅ LGTM
The new code comment describes the current behaviour accurately.
Reviewed commit: 1f9c301d
|
tested with a differential harness against node 26.13 on arm64 and x86_64. the 40960/81920/163840 failures are gone from sync and callback and nothing else changed still broken in the same decoder: input with several frames decodes to just the first one, input starting with a skippable frame decodes to an empty buffer (pzstd writes one before every frame), and a stream fails with "Unknown frame descriptor" when the second frame starts partway into one write and continues into the next. I ported node's frame loop from |
zstdDecompressSync and zstdDecompress threw "unexpected end of file" for a valid frame whose decompressed size exactly filled the sync output buffer: 40960 bytes, and 81920 and 163840 as the buffer doubles (#7923). A full output buffer makes the sync loop call ZSTD_decompressStream once more after all input is consumed. For that call zstd returns the header size of the next frame, and the decoder took any non-zero result as a frame still in progress, because its guard checked input_.size, which is the whole input, not what is left of it. In this patch the decoder marks a frame as in progress only when the call consumed input, and as finished when zstd returns 0. Truncated input is still reported.
zstdDecompressSyncOutputFillsBufferTest decodes frames of 1x to 4x the 40 KiB first sync buffer size, plus and minus one byte, through zstdDecompressSync and zstdDecompress. It fails with "unexpected end of file" without the previous commit.
1f9c301 to
f2c20c2
Compare
There was a problem hiding this comment.
✅ Approved — The fix to frame-in-progress tracking in ZstdDecoderContext::work() is correct and has a regression test. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The new frame-state logic is correct: a return value of 0 ends the frame, a call that reads input marks it in progress, and a call that reads nothing leaves the state unchanged. The regression test covers the buffer-boundary sizes.
📝 Documentation: ✅ LGTM
The new code comment describes the current behaviour accurately.
Reviewed commit: f2c20c21 — same changes as 1f9c301d, so this is that commit's review (no new review was run; line numbers are as of 1f9c301d)
Fixes #7923.
zstdDecompressSyncandzstdDecompressthrew "unexpected end of file" for a valid frame when the decompressed size exactly filled the sync output buffer. That buffer starts at 40960 bytes and doubles, so 81920 and 163840 failed too. When the output buffer is full, the sync loop callsZSTD_decompressStreamonce more after all the input has been read. On that call zstd returns the header size of the next frame. The decoder treated any non-zero result as a frame still in progress, because its guard checkedinput_.size, which is the size of the whole input rather than what is left of it.In this patch the decoder marks a frame as in progress only when the call actually read input, and marks it finished when zstd returns 0. Truncated input still raises the error. The new
zstdDecompressSyncOutputFillsBufferTesttries sizes around 1x to 4x the first buffer size with bothzstdDecompressSyncandzstdDecompress, and it fails without the fix.