TypedArray: coerce length argument once on buffer construction - #1123
Merged
xeioex merged 1 commit intoSep 15, 2026
Merged
Conversation
|
🎉 Thank you for your contribution! It appears you have not yet signed the F5 Contributor License Agreement (CLA), which is required for your changes to be incorporated into an F5 Open Source Software (OSS) project. Please kindly read the F5 CLA and reply on a new comment with the following text to agree: I have hereby read the F5 CLA and agree to its terms You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
xeioex
force-pushed
the
typed-array-length-coerce-once
branch
from
September 15, 2026 02:11
b2bf2dd to
b5b698f
Compare
Previously, njs_typed_array_alloc() passed the length argument through njs_value_to_index() twice, before and after the detached-buffer check, and kept only the second result. The argument's valueOf() was invoked twice, which is observable. The fix is to remove the second conversion.
xeioex
force-pushed
the
typed-array-length-coerce-once
branch
from
September 15, 2026 04:59
b5b698f to
ecfabde
Compare
xeioex
approved these changes
Sep 15, 2026
xeioex
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the patch.
I simplified the commit log because it had factual inaccuracies.
Otherwise LGTM.
Please do The F5 CLA, so I will be able to merge.
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.
Proposed changes
Constructing a typed array from an ArrayBuffer with an explicit length, such as
new Int8Array(buffer, byteOffset, length), runs the length throughnjs_value_to_index()twice innjs_typed_array_alloc(): once before the detached-buffer check and once after it, keeping only the second result. BecauseToIndexevaluates the argument'svalueOf(), the length object'svalueOf()fires twice, which is observable from script and departs both from the specification, whereToIndexruns once, and from theDataViewconstructor, which converts its length a single time. The duplicate conversion also runs after the detached-buffer check, so avalueOf()that detaches the buffer while the length is being coerced slips past the check and the constructor returns a zero-length view over the detached buffer instead of throwing. The fix removes the second conversion so the length is coerced once, before the check. AvalueOf()that detaches mid-coercion is now reported, and valid construction is unchanged. I added a regression test asserting the length argument'svalueOf()is invoked exactly once.Checklist
Before creating a PR, run through this checklist and mark each as complete:
CONTRIBUTINGdocument