Repository navigation
Conversation
|
@lavenzg has exported this pull request. If you are a Meta employee, you can view the originating Diff in D132346566. |
Summary: JSI's default `Runtime::push`, used by runtimes that don't override it such as HermesSandboxRuntime, converted the element indices and the new length to `int`. Once an array's length passes INT_MAX, the elements go to the wrong keys and `length` gets a wrapped value: from length 2^31, `push(1)` throws "Invalid array length"; from length 2^32-1, it silently sets `length` to 0, emptying the array. Fix: convert to `double`, which holds every array index and length exactly, and keep the running length in a `uint64_t` so it can't wrap on 32-bit hosts, where `size_t` is 32 bits. A successful `length` store bounds the result by 2^32-1, so narrowing it to `size_t` on return is safe. Changelog: [Internal] Differential Revision: D132346566
lavenzg
force-pushed
the
export-D132346566
branch
from
November 18, 2026 20:47
5d2d68c to
39b3dfa
Compare
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.



Summary:
JSI's default
Runtime::push, used by runtimes that don't override it such as HermesSandboxRuntime, converted the element indices and the new length toint. Once an array's length passes INT_MAX, the elements go to the wrong keys andlengthgets a wrapped value: from length 2^31,push(1)throws "Invalid array length"; from length 2^32-1, it silently setslengthto 0, emptying the array.Fix: convert to
double, which holds every array index and length exactly, and keep the running length in auint64_tso it can't wrap on 32-bit hosts, wheresize_tis 32 bits. A successfullengthstore bounds the result by 2^32-1, so narrowing it tosize_ton return is safe.Changelog: [Internal]
Differential Revision: D132346566