Skip to content

Fix node:zlib zstd "Unexpected end of file" on valid input#6773

Open
t-kouyama wants to merge 1 commit into
cloudflare:mainfrom
t-kouyama:fix/zstd-compress-eof
Open

Fix node:zlib zstd "Unexpected end of file" on valid input#6773
t-kouyama wants to merge 1 commit into
cloudflare:mainfrom
t-kouyama:fix/zstd-compress-eof

Conversation

@t-kouyama
Copy link
Copy Markdown

Fixes #6769.

Zstd compression could throw "Unexpected end of file" for valid incompressible input because the sync encode path treated a non-zero return from ZSTD_compressStream2(..., ZSTD_e_end) as EOF even when the encoder still had output left to flush.

This change keeps the sync processing loop running while the zstd encoder still has pending input or output, while leaving the zlib and brotli sync paths unchanged. Since the callback-based API routes through the same sync implementation, this fixes both zstdCompressSync and zstdCompress.

The regression test adds a large random-input round-trip case to cover the same pending-output path.

Tests

  • bazel test //src/workerd/api/node/tests:zlib-nodejs-test@
  • bazel test //src/workerd/api/node/tests:zlib-zstd-nodejs-test@

@t-kouyama t-kouyama requested review from a team as code owners May 20, 2026 08:55
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@t-kouyama
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report — Runtime APIs: node:zlib zstdCompressSync fails with Unexpected end of file on valid input

1 participant