zlib: decode concatenated zstd frames - #65911
Open
agape1225 wants to merge 1 commit into
Open
Conversation
A single write can hold several concatenated zstd frames, which the zstd format explicitly allows and which `zstdcat` decodes. When the frame boundary fell inside one input buffer, the zstd decompress context ran a single decode call, and the processing loop treated the leftover input with free output space as the end of the stream, so the remaining frames were dropped. Keep decoding across frame boundaries while input is pending and output space is left, mirroring how the gzip path already handles concatenated members. When `rejectGarbageAfterEnd` is set, stop after the first frame so the trailing frames are reported as junk; the option is now wired through to the zstd decompression context for that purpose. Fixes: nodejs#64741 Refs: nodejs#64748 Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com>
agape1225
force-pushed
the
zlib-zstd-concatenated-frames
branch
from
September 8, 2026 12:50
0fb78f4 to
f93a2bb
Compare
Member
|
duplicates #65865 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65911 +/- ##
==========================================
+ Coverage 90.16% 90.18% +0.02%
==========================================
Files 771 771
Lines 265097 265077 -20
Branches 50358 50344 -14
==========================================
+ Hits 239026 239062 +36
+ Misses 17011 16963 -48
+ Partials 9060 9052 -8
🚀 New features to boost your workflow:
|
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.
A single write to a zstd decompression stream can hold several
concatenated zstd frames. The zstd format explicitly allows this and
zstdcatdecodes it, but Node stopped after the first frame wheneverthe frame boundary fell inside one input buffer:
ZstdDecompressContext::DoThreadPoolWorkran a singleZSTD_decompressStreamcall, and the JS processing loop treated theleftover input with free output space as the end of the stream.
gzipalready handles concatenated members correctly, and the reporter of
the issue hit this in practice after ~3 GB of streamed data.
This keeps decoding across frame boundaries while input is pending and
output space is left, mirroring the gzip multi-member loop. When
rejectGarbageAfterEndis set, it stops after the first frame so thetrailing frames are still reported as junk — the option is now wired
through to the zstd decompression context for that purpose.
rejectGarbageAfterEnd: false+ trailing bytes that are not a validframe now produces a decode error instead of being silently ignored,
which matches gzip's behavior for trailing non-padding garbage.
Fixes: #64741
This re-does #64748 by @lazerg (closed for lack of review) on top of
current
main, keeping the same approach; credited viaCo-authored-by.🤖 Generated with Claude Code