check for integer overflow which could result in buffer overrun when loading an invalid TIFF file
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60876 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
5550f66bce
commit
5beedebb82
@ -286,7 +286,6 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
|
||||
}
|
||||
|
||||
uint32 w, h;
|
||||
uint32 npixels;
|
||||
uint32 *raster;
|
||||
|
||||
TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &w );
|
||||
@ -300,9 +299,20 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos
|
||||
(samplesInfo[0] == EXTRASAMPLE_ASSOCALPHA ||
|
||||
samplesInfo[0] == EXTRASAMPLE_UNASSALPHA));
|
||||
|
||||
npixels = w * h;
|
||||
// guard against integer overflow during multiplication which could result
|
||||
// in allocating a too small buffer and then overflowing it
|
||||
const double bytesNeeded = w * h * sizeof(uint32);
|
||||
if ( bytesNeeded >= wxUINT32_MAX )
|
||||
{
|
||||
if ( verbose )
|
||||
wxLogError( _("TIFF: Image size is abnormally big.") );
|
||||
|
||||
raster = (uint32*) _TIFFmalloc( npixels * sizeof(uint32) );
|
||||
TIFFClose(tif);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
raster = (uint32*) _TIFFmalloc( bytesNeeded );
|
||||
|
||||
if (!raster)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user