Commit cedfe4c
authored
Fix heap-buffer-overflow in constant_pad_nd (pytorch#18018)
Summary:
Fix write-heap-buffer-overflow in set_all_to_value triggered via
apply_padding_to_dim, reported by fuzzer (T258811544).
Root causes:
1. Negative padding values silently cast to huge size_t, causing massive
out-of-bounds writes.
2. When out_data advances past out_data_end, the remaining computation
(out_data_end - out_data) wraps around to a huge size_t, causing bounds
checks to incorrectly pass.
3. No error propagation after recursive apply_padding_to_dim calls,
allowing the loop to continue writing after a child call has failed.
Fixes:
- Validate all padding values are non-negative in
check_constant_pad_args.
- Read padding as int64_t and explicitly check >= 0 before casting to
size_t.
- Guard remaining computation with out_data <= out_data_end check at all
three bounds-check sites to prevent size_t wraparound.
- Check ctx.failure_state() after recursive calls and bail out early.
- Remove dead pad_i >= 0 check (always true for size_t).
Differential Revision: D957623351 parent bad1aec commit cedfe4c
2 files changed
Lines changed: 41 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
| |||
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
65 | 79 | | |
66 | 80 | | |
67 | 81 | | |
| |||
92 | 106 | | |
93 | 107 | | |
94 | 108 | | |
95 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
96 | 115 | | |
97 | 116 | | |
98 | 117 | | |
| |||
123 | 142 | | |
124 | 143 | | |
125 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
126 | 149 | | |
127 | 150 | | |
128 | 151 | | |
| |||
131 | 154 | | |
132 | 155 | | |
133 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
134 | 163 | | |
135 | 164 | | |
136 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
567 | 575 | | |
568 | 576 | | |
569 | 577 | | |
| |||
0 commit comments