Skip to content

zlib: reject trailing gzip members in web streams#64023

Open
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-decompressionstream-trailing-data
Open

zlib: reject trailing gzip members in web streams#64023
panva wants to merge 3 commits into
nodejs:mainfrom
panva:fix-decompressionstream-trailing-data

Conversation

@panva

@panva panva commented Jun 20, 2026

Copy link
Copy Markdown
Member

Pass the existing rejectGarbageAfterEnd option through to the native zlib context and skip gunzip's concatenated-member loop when it is set. This lets DecompressionStream reject a second gzip member as trailing input while preserving default zlib gunzip behavior.

Also make the sync zlib path honor rejectGarbageAfterEnd when native decompression leaves unused input, covering Brotli as well.

Fixes: #58247


Document rejectGarbageAfterEnd as a public decompression option and validate it as a boolean.

Add coverage for stream, async convenience, and sync convenience APIs across zlib, gzip, Brotli, and Zstd-backed decompression.

Pass the existing rejectGarbageAfterEnd option through to the native
zlib context and skip gunzip's concatenated-member loop when it is set.
This lets DecompressionStream reject a second gzip member as trailing
input while preserving default zlib gunzip behavior.

Also make the sync zlib path honor rejectGarbageAfterEnd when native
decompression leaves unused input, covering Brotli as well.

Fixes: nodejs#58247

Signed-off-by: Filip Skokan <[email protected]>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib subsystem. labels Jun 20, 2026
@panva panva requested a review from ChALkeR June 20, 2026 10:56
@panva panva added the commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. label Jun 20, 2026
@panva panva force-pushed the fix-decompressionstream-trailing-data branch from 88f47d2 to 481083c Compare June 20, 2026 11:12
Document rejectGarbageAfterEnd as a public decompression option and
validate it as a boolean.

Add coverage for stream, async convenience, and sync convenience APIs
across zlib, gzip, Brotli, and Zstd-backed decompression.

Signed-off-by: Filip Skokan <[email protected]>
@panva panva force-pushed the fix-decompressionstream-trailing-data branch from 481083c to a47d32d Compare June 20, 2026 11:13
Comment thread doc/api/zlib.md Outdated
[convenience methods][]. **Default:** [`buffer.kMaxLength`][]
* `rejectGarbageAfterEnd` {boolean} If `true`, decompression fails when
trailing input is detected after the end of the compressed stream.
**Default:** `false`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs should be explicit about the fact that this does not just refer to actual "garbage", i.e. unreadable bytes, but also additional gzip streams following the first one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was me i'd name the option different. But alas i'm just documenting one that was already there unfortunately exposed.

That said i can name it better, suggestion?, and alias one for the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DecompressionStream should not accept data after the end

3 participants