Skip to content

Fix int truncation in JSI's default Runtime::push (#60062) - #60062

Open
lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D132346566
Open

lavenzg wants to merge 1 commit into
react:mainfrom
lavenzg:export-D132346566

Conversation

@lavenzg

@lavenzg lavenzg commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 17, 2026
@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown

@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
@meta-codesync meta-codesync Bot changed the title Fix int truncation in JSI's default Runtime::push Fix int truncation in JSI's default Runtime::push (#60062) Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

1 visual difference(s) at 39b3dfa83e19. Visual differences need maintainer approval. Review the report, then apply visual-change-approved.

ios touchable/highlight/default: Changed, 42 px (0.039%)

diff

Expected and Captured
Expected Captured
expected captured

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant