Repository navigation
Conversation
encodeInto() wrote into a Uint8Array backed by an immutable ArrayBuffer created with transferToImmutable(). Check the backing store before either write path and throw ERR_INVALID_ARG_VALUE, matching websocketMask(). Fixes: nodejs#66346 Signed-off-by: Chidiebere Ekennia <54110155+Davien21@users.noreply.github.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
Context
encodeInto()was writing into aUint8Arrayeven when its buffer came fromtransferToImmutable(), so it changed memory that's supposed to be read-only.Now it throws
ERR_INVALID_ARG_VALUEand the bytes are left alone.Fixes: #66346 This is part of the immutable ArrayBuffer audit.
The check is in the C++ binding, before either write path, so the short-string path and the fast path for long strings are both covered. When the buffer is immutable the binding returns
falseand the JS side throws, with the same error code and message aswebsocketMask().One thing I wasn't sure about: an empty string into a zero-length immutable view also throws, rather than quietly doing nothing. I went with consistency, but I'm happy to change it if you'd rather it be a no-op?
I added
test/parallel/test-whatwg-encoding-custom-textencoder-immutable.js, which tries empty, short, accented, long, multi-byte and lone-surrogate strings against whole, offset and zero-length views. I built Node locally on macOS (arm64), andtools/test.py test/parallel/test-whatwg-encoding-*passed, as didmake lint-js lint-cpp.