Lines 134-143
Link Here
|
134 |
% |
134 |
% |
135 |
*/ |
135 |
*/ |
136 |
static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels, |
136 |
static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels, |
137 |
const size_t length,unsigned char *pixels) |
137 |
const size_t length,unsigned char *pixels,size_t maxpixels) |
138 |
{ |
138 |
{ |
139 |
register const unsigned char |
139 |
register const unsigned char |
140 |
*p; |
140 |
*p, *l; |
141 |
|
141 |
|
142 |
register unsigned char |
142 |
register unsigned char |
143 |
*q; |
143 |
*q; |
Lines 153-159
Link Here
|
153 |
assert(pixels != (unsigned char *) NULL); |
153 |
assert(pixels != (unsigned char *) NULL); |
154 |
p=compressed_pixels; |
154 |
p=compressed_pixels; |
155 |
q=pixels; |
155 |
q=pixels; |
156 |
while ((size_t) (p-compressed_pixels) < length) |
156 |
l=q+maxpixels; |
|
|
157 |
while ((size_t) (p-compressed_pixels) < length && q < l) |
157 |
{ |
158 |
{ |
158 |
byte=(*p++); |
159 |
byte=(*p++); |
159 |
if (byte != 128U) |
160 |
if (byte != 128U) |
Lines 166-172
Link Here
|
166 |
count=(ssize_t) (*p++); |
167 |
count=(ssize_t) (*p++); |
167 |
if (count > 0) |
168 |
if (count > 0) |
168 |
byte=(*p++); |
169 |
byte=(*p++); |
169 |
while (count >= 0) |
170 |
while (count >= 0 && q < l) |
170 |
{ |
171 |
{ |
171 |
*q++=byte; |
172 |
*q++=byte; |
172 |
count--; |
173 |
count--; |
Lines 378-383
Link Here
|
378 |
CloseBlob(image); |
379 |
CloseBlob(image); |
379 |
return(GetFirstImageInList(image)); |
380 |
return(GetFirstImageInList(image)); |
380 |
} |
381 |
} |
|
|
382 |
if ((sun_info.length * sizeof(*sun_data)) / sizeof(*sun_data) != sun_info.length || !sun_info.length) |
383 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
381 |
sun_data=(unsigned char *) |
384 |
sun_data=(unsigned char *) |
382 |
AcquireMagickMemory((size_t) sun_info.length*sizeof(*sun_data)); |
385 |
AcquireMagickMemory((size_t) sun_info.length*sizeof(*sun_data)); |
383 |
if (sun_data == (unsigned char *) NULL) |
386 |
if (sun_data == (unsigned char *) NULL) |
Lines 395-405
Link Here
|
395 |
Read run-length encoded raster pixels. |
398 |
Read run-length encoded raster pixels. |
396 |
*/ |
399 |
*/ |
397 |
height=sun_info.height; |
400 |
height=sun_info.height; |
398 |
bytes_per_line=2*(sun_info.width*sun_info.depth+15)/16; |
401 |
|
|
|
402 |
/* calculate bytes per line, verifying no overflow occurs */ |
403 |
bytes_per_line=sun_info.width*sun_info.depth; |
404 |
if (!height || !sun_info.width || !sun_info.depth || bytes_per_line / sun_info.depth != sun_info.width) |
405 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
406 |
|
407 |
if ((ULONG_MAX - bytes_per_line) < 15) |
408 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
409 |
|
410 |
bytes_per_line += 15; |
411 |
bytes_per_line <<= 1; |
412 |
if (bytes_per_line >> 1 != sun_info.width * sun_info.depth + 15) |
413 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
414 |
|
415 |
bytes_per_line >>= 4; |
416 |
if ((bytes_per_line * height) / height != bytes_per_line) |
417 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
418 |
|
399 |
sun_pixels=(unsigned char *) AcquireMagickMemory(bytes_per_line*height); |
419 |
sun_pixels=(unsigned char *) AcquireMagickMemory(bytes_per_line*height); |
400 |
if (sun_pixels == (unsigned char *) NULL) |
420 |
if (sun_pixels == (unsigned char *) NULL) |
401 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
421 |
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
402 |
(void) DecodeImage(sun_data,sun_info.length,sun_pixels); |
422 |
(void) DecodeImage(sun_data,sun_info.length,sun_pixels, bytes_per_line * height); |
403 |
sun_data=(unsigned char *) RelinquishMagickMemory(sun_data); |
423 |
sun_data=(unsigned char *) RelinquishMagickMemory(sun_data); |
404 |
} |
424 |
} |
405 |
/* |
425 |
/* |