Commit 586acfb
authored
Avoid potential integer overflow in Mmap.mmap (#41186)
There is a potential integer overflow in Mmap.mmap which can lead to an
out-of-bounds access. The size of the memory-mapped array `len` is
calculated as `prod(dims)`. If this multiplication overflows, the
allocated size will be too small and accesses towards the end of the
array will fail with e.g. a segfault or other errors. I noticed this
when using `dims` taken from a binary file header in UInt32 format.
To fix, use overflow-aware multiplication to determine the size of the
mmapped array and throw an error in case of overflow.1 parent 6182eef commit 586acfb
2 files changed
+6
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
0 commit comments