Commit beca948
authored
Add integer overflow checks in Program::LoadSegment (pytorch#19268)
Summary:
Add overflow protection to pointer arithmetic in `LoadSegment()` and
`load_mutable_subsegment_into()`.
Three additions were unchecked:
1. `segment_base_offset_ + segment->offset()` in `LoadSegment()` (line
563) — a malicious `.pte` file can set `segment->offset()` near
`UINT64_MAX`, wrapping the sum to a small value and causing the loader
to read from an unintended file position.
2. `offset + size` in `load_mutable_subsegment_into()` — overflow before
the bounds check against `segment->size()` would bypass the validation
entirely.
3. `segment_base_offset_ + segment->offset() + offset` in
`load_mutable_subsegment_into()` (line 649) — a triple addition with no
overflow check on any intermediate result. Now computed in two validated
steps.
The overflow checks use the same `ET_CHECK_OR_RETURN_ERROR` pattern
already established at lines 95-100 for the header-level segment
validation.
MACA-2026-001 (T266924552).
Differential Revision: D1034677841 parent 7ceccdf commit beca948
1 file changed
Lines changed: 41 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
563 | 574 | | |
564 | | - | |
| 575 | + | |
565 | 576 | | |
566 | 577 | | |
567 | 578 | | |
| |||
628 | 639 | | |
629 | 640 | | |
630 | 641 | | |
631 | | - | |
632 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
633 | 651 | | |
634 | 652 | | |
635 | 653 | | |
| |||
644 | 662 | | |
645 | 663 | | |
646 | 664 | | |
647 | | - | |
648 | | - | |
649 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
650 | 685 | | |
651 | 686 | | |
652 | 687 | | |
| |||
0 commit comments