]> granicus.if.org Git - imagemagick/commitdiff
Fixed calculation of extent (https://oss-fuzz.com/v2/testcase-detail/6597619229917184).
authorDirk Lemstra <dirk@git.imagemagick.org>
Tue, 10 Apr 2018 18:31:44 +0000 (20:31 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Tue, 10 Apr 2018 18:31:44 +0000 (20:31 +0200)
coders/pnm.c

index d3a5d092b6fff678439d32d70a734897252d756c..e380361267748ce5c5e3d1bcc3e343cd8c4580b1 100644 (file)
@@ -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");