Skip to content

Commit

Permalink
eliminate possible buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jun 29, 2022
1 parent f0a0274 commit 2b4eabb
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions coders/tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,12 +1794,7 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
/*
Convert stripped TIFF image.
*/
extent=(samples_per_pixel+1)*TIFFStripSize(tiff);
#if defined(TIFF_VERSION_BIG)
extent+=samples_per_pixel*sizeof(uint64);
#else
extent+=samples_per_pixel*sizeof(uint32);
#endif
extent=4*(samples_per_pixel+1)*TIFFStripSize(tiff);
strip_pixels=(unsigned char *) AcquireQuantumMemory(extent,
sizeof(*strip_pixels));
if (strip_pixels == (unsigned char *) NULL)
Expand Down Expand Up @@ -1894,13 +1889,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
number_pixels=(MagickSizeType) columns*rows;
if (HeapOverflowSanityCheck(rows,sizeof(*tile_pixels)) != MagickFalse)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
extent=(samples_per_pixel+1)*MagickMax(rows*TIFFTileRowSize(tiff),
extent=4*(samples_per_pixel+1)*MagickMax(rows*TIFFTileRowSize(tiff),
TIFFTileSize(tiff));
#if defined(TIFF_VERSION_BIG)
extent+=samples_per_pixel*sizeof(uint64);
#else
extent+=samples_per_pixel*sizeof(uint32);
#endif
tile_pixels=(unsigned char *) AcquireQuantumMemory(extent,
sizeof(*tile_pixels));
if (tile_pixels == (unsigned char *) NULL)
Expand Down Expand Up @@ -1996,11 +1986,6 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
if (HeapOverflowSanityCheck(image->rows,sizeof(*pixels)) != MagickFalse)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
number_pixels=(MagickSizeType) image->columns*image->rows;
#if defined(TIFF_VERSION_BIG)
number_pixels+=samples_per_pixel*sizeof(uint64);
#else
number_pixels+=samples_per_pixel*sizeof(uint32);
#endif
generic_info=AcquireVirtualMemory(number_pixels,sizeof(*pixels));
if (generic_info == (MemoryInfo *) NULL)
ThrowTIFFException(ResourceLimitError,"MemoryAllocationFailed");
Expand Down

0 comments on commit 2b4eabb

Please sign in to comment.