Repository navigation
fix(ext/node): select the detached-buffer contract of isAscii and isUtf8 - #32
Merged
Merged
Conversation
Node.js 24.21 and 26.8 (nodejs/node#64504) treat a detached ArrayBuffer, or a view backed by one, as empty input: buffer.isAscii() and buffer.isUtf8() return true. Earlier releases throw ERR_INVALID_STATE. Add BufferDetachedValidationPolicy so that an embedder selects the contract of its Node.js target. Deno keeps Throw, because its node_compat suite tracks Node.js 26.5.1. The TreatAsEmpty path returns before it builds a Uint8Array, because the constructor throws for a detached ArrayBuffer. Run buffer_test in the Nimbus fork CI.
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.
Summary
Node.js changed how
buffer.isAscii()andbuffer.isUtf8()treat a detachedArrayBuffer(nodejs/node#64504):ERR_INVALID_STATE: "Cannot validate on a detached buffer".true. This applies to a detachedArrayBufferand to aBufferorTypedArrayview backed by one.The fork always threw. The Nimbus node24 (v24.21.0) and node26 (v26.10.0) lanes fail
test-buffer-isascii.jsandtest-buffer-isutf8.jsfor this reason.Change
deno_node::BufferDetachedValidationPolicywithThrowandTreatAsEmpty. The embedder passes it in thedeno_nodeoptions, the same as the other versioned Node policies.op_node_buffer_detached_validation_throwsreads the policy. With no policy in the state, it keepsThrow, which is the upstream behavior.isAscii()andisUtf8()share one detached check. ForTreatAsEmpty, they returntruebefore they build aUint8Array, because that constructor throws for a detachedArrayBuffer.Throw. Deno's node_compat suite tracks Node.js 26.5.1, which throws.buffer_test.Upstream Deno main still throws. This is a temporary carry. Removal trigger: upstream Deno adopts the nodejs/node#64504 contract for the Node.js versions that it targets.
Verification (macOS arm64)
unit_node buffer_test: ok. The new test coversisAsciiandisUtf8with a detachedArrayBuffer,Buffer,Uint8Array, andFloat64Array.node_compat test-buffer-is*: 4 passed (test-buffer-isascii.js,test-buffer-isutf8.js,test-buffer-isutf8-isascii-fast.js,test-buffer-isencoding.js).cargo test -p deno_node --lib --features deno_core/default policy: 5 passed, including the new policy test.cargo fmt --checkand dprint with.dprint.json: clean.The Nimbus consumer maps node20 and node22 to
Throw, and node24, node26, and the non-Node targets toTreatAsEmpty. That change lands with the next Nimbus repin.