fix(ext/node): avoid trailing empty zstd frames - #36689
Open
ArakawaHenri wants to merge 2 commits into
Open
Conversation
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.
Fixes #36688
ZstdCompresspreviously implemented an end write asrun()followed byfinish(). When the output buffer filled, the retry could insertZSTD_e_continueinto an in-progressZSTD_e_endoperation and append an empty frame.This change:
ZSTD_compressStream2()once per write, preserving the requestedcontinue,flush, orenddirective across output chunks;ZSTD_e_endcompletes while exactly filling the output buffer, preventing the following empty-input retry from starting another frame;Node parity
Node v26.7.0 passes its stored flush directive directly to
ZSTD_compressStream2(). Matching that behavior restores Node parity for ordinary multi-chunk output.Node's
processChunkloop retries wheneveravailOutAfter === 0, so Node v26.7.0 currently appends an empty frame in the exact-fill case as well. This PR intentionally does not reproduce that boundary artifact: it depends only on internal output-buffer allocation and breaks consumers that validate exactly one frame. The return value fromZSTD_compressStream2()allows Deno to distinguish completed output from pending output.The parity fix and the exact-fill guard are split into separate commits. If strict parity with Node's current exact-fill behavior is preferred, the first commit can be taken on its own.
Tests
./tools/format.js --checkcargo check -p deno_node --features deno_core/v8./x test-node zstd./tools/lint.jsAI disclosure: ChatGPT assisted with bug investigation and patch implementation. I reviewed the changes and test results.