LibJS: Avoid potential overflow in Array.prototype.toSpliced()#14466
Merged
linusg merged 1 commit intoSerenityOS:masterfrom Jul 3, 2022
Merged
LibJS: Avoid potential overflow in Array.prototype.toSpliced()#14466linusg merged 1 commit intoSerenityOS:masterfrom
linusg merged 1 commit intoSerenityOS:masterfrom
Conversation
The implementation no longer matches the spec text, but I believe that's a bug anyway. No point in allowing array lengths up to 2^53 - 1 when the ArrayCreate AO rejects anything above 2^32 - 1.
IdanHo
approved these changes
Jul 2, 2022
Comment on lines
+1927
to
1931
| // FIXME: ArrayCreate throws for any length > 2^32 - 1, so there's no point in letting | ||
| // values up to 2^53 - 1 through (spec issue). This also prevents a potential | ||
| // overflow when casting from double to size_t, which is 32 bits on x86. | ||
| if (new_length_double > NumericLimits<u32>::max()) | ||
| return vm.throw_completion<TypeError>(global_object, ErrorType::ArrayMaxSize); |
Member
There was a problem hiding this comment.
That's a good point, generally Array prototype methods allow up to MAX_ARRAY_LIKE_INDEX and not just 2^32 - 1, since they are supposed to be generic, so you can use them on other objects like strings that do not have this limitation, but these toX class of methods create arrays, so they do have to use the smaller maximum, which is the array maximum size.
Member
Author
There was a problem hiding this comment.
Filed tc39/proposal-change-array-by-copy#94 for this :)
3 tasks
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.
No description provided.