fix(ext/node): make zlib writeSync _writeState argument optional (#35185)#35207
Open
tsushanth wants to merge 4 commits into
Open
fix(ext/node): make zlib writeSync _writeState argument optional (#35185)#35207tsushanth wants to merge 4 commits into
tsushanth wants to merge 4 commits into
Conversation
Deno Individual Contributor License AgreementThe following contributors need to sign the CLA before this PR can be merged: Click here to review and sign the CLA | Re-run CLA check This is an automated message from CLA Assistant |
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.
Closes #35185. Compat regression introduced by #35043.
#35043 moved the zlib write-result buffer (
_writeState) from a pointer cached at handle init to a per-call argument on_handle.writeSync(...). The Rust op required it (#[buffer] write_result: &mut [u32]), so callers that bind directly to_handle.writeSyncand never knew about per-call state — notablypngjs'ssync-inflate.js, which is whatpng-to-ico(and the reporter'sfount) pull in — now hitTypeError: expected typed ArrayBufferViewwhen v8 seesundefinedfor the 8th slot. The high-levelzlib.inflateSync/ asyncPNG.parse()paths are unaffected because Deno's ownzlib.jsalways passes the buffer.This makes the per-call result buffer optional in the Inflate op signature:
#[buffer] write_result: Option<&mut [u32]>if let Some(write_result) = write_resultWhen a caller does pass a state buffer (which Deno's polyfill, and any post-#35043 external code, does), the behavior is byte-for-byte identical — the security fix for the detached-buffer case is preserved because the per-call argument is still validated as a typed array. When a caller doesn't, the op just runs the inflate/deflate step without surfacing the post-write avail counts; the legacy contract for pngjs (which then reads its own bookkeeping) is restored.
Scope: the BrotliEncoder / BrotliDecoder / ZstdCompress / ZstdDecompress ops have the same
write_result: &mut [u32]parameter, but I deliberately left them as-is. They postdate the pngjs era and we don't have an external caller report against them; the Inflate path is the one with a confirmed in-the-wild compat regression. Happy to widen the fix in a follow-up if the team prefers symmetry.Tests
Added
"zlib writeSync accepts the pre-#35043 seven-argument signature"intests/unit_node/zlib_test.ts, mirroring the reporter's minimal repro: azlib.createInflate()whose_handle.writeSyncis invoked with seven arguments must not throw. Pre-fix this throwsTypeError: expected typed ArrayBufferView; post-fix it returns successfully.The detached-
_writeStatetests added by #35043 (writeSync does not write through a detached _writeState,writeSync populates _writeState per call) continue to pass since they exercise the eight-argument path that this PR doesn't change.