Repository navigation
Conversation
Function.prototype.apply, Reflect.apply and Reflect.construct read the length of the argument list with ToUint32, so a negative length turned into 2^32 - 1 and threw a RangeError, and a length above 2^32 wrapped around. CreateListFromArrayLike uses LengthOfArrayLike, which clamps negative values to 0. Fixes: quickjs-ng#1764
bnoordhuis
approved these changes
Oct 9, 2026
bnoordhuis
left a comment
Contributor
There was a problem hiding this comment.
LGTM and good catch but this suggests to me that we should either:
- change
js_get_length32so it clamps values instead of wrapping, or - excise it from the code base altogether
This branch has not been deployed
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.
build_arg_list() read the length of the array-like with ToUint32, so
f.apply(null, { length: -1 })threw "RangeError: too many arguments in function call" and a length like 2 ** 32 + 1 wrapped around to 1. CreateListFromArrayLike goes through LengthOfArrayLike (ToLength), which clamps negative values to 0. The same helper backs Reflect.apply and Reflect.construct, so those are fixed too.The length is now read with js_get_length64() and checked against the argument limit before narrowing. With the patch:
Added cases to test_function in tests/test_builtin.js (they fail without the change). make test passes and make test262 shows no change against test262_errors.txt.
Fixes #1764