|
Dan Horák |
c10dad |
Index: src/common/imagpng.cpp
|
|
Dan Horák |
c10dad |
===================================================================
|
|
Dan Horák |
c10dad |
--- src/common/imagpng.cpp (revision 60874)
|
|
Dan Horák |
c10dad |
+++ src/common/imagpng.cpp (revision 60875)
|
|
Dan Horák |
c10dad |
@@ -568,18 +568,16 @@
|
|
Dan Horák |
c10dad |
if (!image->Ok())
|
|
Dan Horák |
c10dad |
goto error;
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
- lines = (unsigned char **)malloc( (size_t)(height * sizeof(unsigned char *)) );
|
|
Dan Horák |
c10dad |
+ // initialize all line pointers to NULL to ensure that they can be safely
|
|
Dan Horák |
c10dad |
+ // free()d if an error occurs before all of them could be allocated
|
|
Dan Horák |
c10dad |
+ lines = (unsigned char **)calloc(height, sizeof(unsigned char *));
|
|
Dan Horák |
c10dad |
if ( !lines )
|
|
Dan Horák |
c10dad |
goto error;
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
for (i = 0; i < height; i++)
|
|
Dan Horák |
c10dad |
{
|
|
Dan Horák |
c10dad |
if ((lines[i] = (unsigned char *)malloc( (size_t)(width * (sizeof(unsigned char) * 4)))) == NULL)
|
|
Dan Horák |
c10dad |
- {
|
|
Dan Horák |
c10dad |
- for ( unsigned int n = 0; n < i; n++ )
|
|
Dan Horák |
c10dad |
- free( lines[n] );
|
|
Dan Horák |
c10dad |
goto error;
|
|
Dan Horák |
c10dad |
- }
|
|
Dan Horák |
c10dad |
}
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
png_read_image( png_ptr, lines );
|
|
Dan Horák |
c10dad |
Index: src/common/imagtiff.cpp
|
|
Dan Horák |
c10dad |
===================================================================
|
|
Dan Horák |
c10dad |
--- src/common/imagtiff.cpp (revision 60875)
|
|
Dan Horák |
c10dad |
+++ src/common/imagtiff.cpp (revision 60876)
|
|
Dan Horák |
c10dad |
@@ -261,7 +261,6 @@
|
|
Dan Horák |
c10dad |
}
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
uint32 w, h;
|
|
Dan Horák |
c10dad |
- uint32 npixels;
|
|
Dan Horák |
c10dad |
uint32 *raster;
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &w );
|
|
Dan Horák |
c10dad |
@@ -275,10 +274,21 @@
|
|
Dan Horák |
c10dad |
(samplesInfo[0] == EXTRASAMPLE_ASSOCALPHA ||
|
|
Dan Horák |
c10dad |
samplesInfo[0] == EXTRASAMPLE_UNASSALPHA));
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
- npixels = w * h;
|
|
Dan Horák |
c10dad |
+ // guard against integer overflow during multiplication which could result
|
|
Dan Horák |
c10dad |
+ // in allocating a too small buffer and then overflowing it
|
|
Dan Horák |
c10dad |
+ const double bytesNeeded = w * h * sizeof(uint32);
|
|
Dan Horák |
c10dad |
+ if ( bytesNeeded >= 4294967295U /* UINT32_MAX */ )
|
|
Dan Horák |
c10dad |
+ {
|
|
Dan Horák |
c10dad |
+ if ( verbose )
|
|
Dan Horák |
c10dad |
+ wxLogError( _("TIFF: Image size is abnormally big.") );
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
- raster = (uint32*) _TIFFmalloc( npixels * sizeof(uint32) );
|
|
Dan Horák |
c10dad |
+ TIFFClose(tif);
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
+ return false;
|
|
Dan Horák |
c10dad |
+ }
|
|
Dan Horák |
c10dad |
+
|
|
Dan Horák |
c10dad |
+ raster = (uint32*) _TIFFmalloc( bytesNeeded );
|
|
Dan Horák |
c10dad |
+
|
|
Dan Horák |
c10dad |
if (!raster)
|
|
Dan Horák |
c10dad |
{
|
|
Dan Horák |
c10dad |
if (verbose)
|
|
Dan Horák |
c10dad |
Index: src/common/imagtiff.cpp
|
|
Dan Horák |
c10dad |
===================================================================
|
|
Dan Horák |
c10dad |
--- src/common/imagtiff.cpp (revision 60896)
|
|
Dan Horák |
c10dad |
+++ src/common/imagtiff.cpp (revision 60897)
|
|
Dan Horák |
c10dad |
@@ -276,7 +276,7 @@
|
|
Dan Horák |
c10dad |
|
|
Dan Horák |
c10dad |
// guard against integer overflow during multiplication which could result
|
|
Dan Horák |
c10dad |
// in allocating a too small buffer and then overflowing it
|
|
Dan Horák |
c10dad |
- const double bytesNeeded = w * h * sizeof(uint32);
|
|
Dan Horák |
c10dad |
+ const double bytesNeeded = (double)w * (double)h * sizeof(uint32);
|
|
Dan Horák |
c10dad |
if ( bytesNeeded >= 4294967295U /* UINT32_MAX */ )
|
|
Dan Horák |
c10dad |
{
|
|
Dan Horák |
c10dad |
if ( verbose )
|