From ef4d021ea94df2c7f53baffdf6667af54fc27401 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Tue, 10 Apr 2018 20:31:44 +0200 Subject: [PATCH] Fixed calculation of extent (https://oss-fuzz.com/v2/testcase-detail/6597619229917184). --- coders/pnm.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/coders/pnm.c b/coders/pnm.c index d3a5d092b..e38036126 100644 --- a/coders/pnm.c +++ b/coders/pnm.c @@ -635,14 +635,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) */ (void) SetImageColorspace(image,GRAYColorspace,exception); quantum_type=GrayQuantum; - if (image->depth <= 8) - extent=image->columns; - else - if (image->depth <= 16) - extent=2*image->columns; - else - extent=4*image->columns; - quantum_info=AcquireQuantumInfo(image_info,image); + extent=3*(image->depth <= 8 ? 1 : image->depth <= 16 ? 2 : 4)* + image->columns; if (quantum_info == (QuantumInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y++) @@ -750,7 +744,8 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) Convert PNM raster image to pixel packets. */ quantum_type=RGBQuantum; - extent=3*(image->depth <= 8 ? 1 : 2)*image->columns; + extent=3*(image->depth <= 8 ? 1 : image->depth <= 16 ? 2 : 4)* + image->columns; quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); -- 2.40.0