Opened 8 years ago

Last modified 8 years ago

#6448 closed defect

gdalwarp failed — at Version 1

Reported by: liminlu0314 Owned by: warmerdam
Priority: normal Milestone: 1.11.5
Component: Algorithms Version:
Severity: normal Keywords: gdalwarp, int overflow
Cc:

Description (last modified by liminlu0314)

When the value of GDALWarpOptions::dfWarpMemoryLimit is set to be very large, such as 10 GB, the program will fail, because the size of allocated memory overflows. The original code is as below:

gdalwarpoperation.cpp line 2059

    if( *ppMask == NULL )
    {
        int nBytes; //this line should be GIntBig nBytes;

        if( nBitsPerPixel == 32 )
            nBytes = (nXSize * nYSize + nExtraElts) * 4;
        else
            nBytes = (nXSize * nYSize + nExtraElts + 31) / 8;

        *ppMask = VSI_MALLOC_VERBOSE( nBytes );

        if( *ppMask == NULL )
        {
            return CE_Failure;
        }

        memset( *ppMask, nDefault, nBytes );
    }

The modified code is as follows:

    if( *ppMask == NULL )
    {
        GIntBig  nBytes; 

        if( nBitsPerPixel == 32 )
            nBytes = ((GIntBig )nXSize * nYSize + nExtraElts) * 4;
        else
            nBytes = ((GIntBig )nXSize * nYSize + nExtraElts + 31) / 8;

        *ppMask = VSI_MALLOC_VERBOSE( nBytes );

        if( *ppMask == NULL )
        {
            return CE_Failure;
        }

        memset( *ppMask, nDefault, nBytes );
    }

Change History (2)

by liminlu0314, 8 years ago

Attachment: gdal_bug.jpg added

comment:1 by liminlu0314, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.