Repository navigation
Commit 5d2d68c
Fix int truncation in JSI's default Runtime::push
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: D1323465661 parent c1acb2b commit 5d2d68c
2 files changed
Lines changed: 20 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
| 463 | + | |
464 | 464 | | |
465 | | - | |
| 465 | + | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
469 | | - | |
| 468 | + | |
| 469 | + | |
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2557 | 2557 | | |
2558 | 2558 | | |
2559 | 2559 | | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
2560 | 2576 | | |
2561 | 2577 | | |
2562 | 2578 | | |
| |||
0 commit comments