Commit 527c86b
committed
mmap: bound find/rfind by the needle rather than clamping the subtraction
The scan's upper bound is `span - len(needle)`, written as a saturating
subtraction. When the needle is longer than the span that clamps to 0, which
still leaves index 0 to try, and reading a needle-sized window there indexes
past the end of the span: `mmap.find(b"ab")` on a one-byte map aborts the
interpreter with "range end index 2 out of range for slice of length 1".
Reject the case before the scan instead, in both find and rfind, and give the
empty needle its own answer: it matches at the near end of the span, `start`
for find and `end` for rfind, where the shared `start >= end || is_empty`
guard used to fold it into -1 along with the inverted-span case.
test_mmap stops aborting and reports its remaining failures normally
(51 tests, 3 failures + 21 errors).
test_mmap's own sweep already covers the oversized needle — `test_find_end`
walks every start/end pair against `bytes.find` as the oracle, which is where
the abort came from — but its pattern list has no empty needle, and that module
is not in the suite gate. The parity fixture therefore carries the empty-needle
half, keeps the oversized cases beside it so the two halves of one bound stay
together, and pins values rather than the absence of the abort. It fails on the
unpatched binary.
Verified on dynasm; parity_tests green. The cranelift binary in this tree
predates the change.
Assisted-by: Claude1 parent 424da05 commit 527c86b
2 files changed
Lines changed: 93 additions & 4 deletions
File tree
- pyre
- extra_tests/parity_tests
- pyre-interpreter/src/module/mmap
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
676 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
677 | 683 | | |
678 | 684 | | |
679 | 685 | | |
680 | | - | |
| 686 | + | |
681 | 687 | | |
682 | 688 | | |
683 | 689 | | |
| |||
727 | 733 | | |
728 | 734 | | |
729 | 735 | | |
730 | | - | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
731 | 743 | | |
732 | 744 | | |
733 | 745 | | |
734 | | - | |
| 746 | + | |
735 | 747 | | |
736 | 748 | | |
737 | 749 | | |
| |||
0 commit comments