Skip to content

Commit 4e0d9b0

Browse files
nedwillwiredfool
authored andcommitted
fix integer overflow in Resample.c
1 parent bdd86b7 commit 4e0d9b0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libImaging/Resample.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,23 @@ ImagingResampleHorizontal(Imaging imIn, int xsize, int filter)
138138
/* maximum number of coofs */
139139
kmax = (int) ceil(support) * 2 + 1;
140140

141+
// check for overflow
142+
if (kmax > 0 && xsize > SIZE_MAX / kmax)
143+
return (Imaging) ImagingError_MemoryError();
144+
145+
// sizeof(float) should be greater than 0
146+
if (xsize * kmax > SIZE_MAX / sizeof(float))
147+
return (Imaging) ImagingError_MemoryError();
148+
141149
/* coefficient buffer */
142150
kk = malloc(xsize * kmax * sizeof(float));
143151
if ( ! kk)
144152
return (Imaging) ImagingError_MemoryError();
145153

154+
// sizeof(int) should be greater than 0 as well
155+
if (xsize > SIZE_MAX / (2 * sizeof(int)))
156+
return (Imaging) ImagingError_MemoryError();
157+
146158
xbounds = malloc(xsize * 2 * sizeof(int));
147159
if ( ! xbounds) {
148160
free(kk);

0 commit comments

Comments
 (0)