Skip to content

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

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
lavenzg:export-D132346566
Nov 20, 2026
Merged

meta-codesync[bot] merged 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]

Reviewed By: avp

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.

@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
lavenzg added a commit to lavenzg/react-native that referenced this pull request Nov 18, 2026
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
@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

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]

Reviewed By: avp

Differential Revision: D132346566
meta-codesync Bot pushed a commit to meta/hermes that referenced this pull request Nov 20, 2026
Summary:
X-link: react/react-native#60062

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]

Reviewed By: avp

Differential Revision: D132346566

fbshipit-source-id: 1204e51bf5cc91dc61816220bf46ac1f8e948d31
meta-codesync Bot pushed a commit to meta/hermes that referenced this pull request Nov 20, 2026
Summary:
X-link: react/react-native#60062

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]

Reviewed By: avp

Differential Revision: D132346566

fbshipit-source-id: 1204e51bf5cc91dc61816220bf46ac1f8e948d31
meta-codesync Bot pushed a commit to meta/hermes that referenced this pull request Nov 20, 2026
Summary:
X-link: react/react-native#60062

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]

Reviewed By: avp

Differential Revision: D132346566

fbshipit-source-id: 1204e51bf5cc91dc61816220bf46ac1f8e948d31
@meta-codesync
meta-codesync Bot merged commit 05c0d3d into react:main Nov 20, 2026
87 of 88 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @lavenzg in 05c0d3d

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 20, 2026
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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants