Commit c9f6df1
authored
Prevent signed integer overflow in pixel_shuffle size calculation (#16138)
Summary:
The size calculation in `get_pixel_shuffle_out_target_size` can trigger
signed integer overflow (UB) with very large upscale_factors. This
manifested as an integer division by zero fault during fuzzing.
Specifically, the calculation of `upscale_factor * upscale_factor`
([source](https://github.com/pytorch/executorch/blob/04f1e4d22383ffcbc770acf5002348e3f95082a2/kernels/portable/cpu/util/copy_ops_util.cpp#L364))
can overflow. In the motivating case, SizesType is a signed 32-bit
integer and upscale_factor = 2^17.
Since this is an impractically large upscale factor, I'm just adding a
constraint that upscale_factor < 32768 (2^15). In theory, SizesType
could be defined as less than 32 bits, but this seems unlikely in
practice. I check this upper bound in `check_pixel_shuffle_args` and
also assert in `get_pixel_shuffle_out_target_size` to ensure we don't
hit UB.
Differential Revision: D886933241 parent f26f228 commit c9f6df1
File tree
3 files changed
+14
-4
lines changed- kernels/portable/cpu
- util
3 files changed
+14
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
354 | 358 | | |
355 | 359 | | |
356 | 360 | | |
| |||
366 | 370 | | |
367 | 371 | | |
368 | 372 | | |
| 373 | + | |
| 374 | + | |
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
0 commit comments