Browse Source

engine: common: imagelib: img_tga.c: check pixel type before buffer allocation.

pull/2/head
Andrey Akhmichin 5 years ago
parent
commit
f5783ae1df
  1. 31
      engine/common/imagelib/img_tga.c

31
engine/common/imagelib/img_tga.c

@ -241,9 +241,22 @@ qboolean Image_SaveTGA( const char *name, rgbdata_t *pix )
if( FS_FileExists( name, false ) && !Image_CheckFlag( IL_ALLOW_OVERWRITE )) if( FS_FileExists( name, false ) && !Image_CheckFlag( IL_ALLOW_OVERWRITE ))
return false; // already existed return false; // already existed
if( pix->flags & IMAGE_HAS_ALPHA ) // bogus parameter check
outsize = pix->width * pix->height * 4 + 18 + Q_strlen( comment ); if( !pix->buffer )
else outsize = pix->width * pix->height * 3 + 18 + Q_strlen( comment ); return false;
// get image description
switch( pix->type )
{
case PF_RGB_24:
case PF_BGR_24: pixel_size = 3; break;
case PF_RGBA_32:
case PF_BGRA_32: pixel_size = 4; break;
default:
return false;
}
outsize = pix->width * pix->height * pixel_size + 18 + Q_strlen( comment );
buffer = (byte *)Mem_Calloc( host.imagepool, outsize ); buffer = (byte *)Mem_Calloc( host.imagepool, outsize );
@ -259,18 +272,6 @@ qboolean Image_SaveTGA( const char *name, rgbdata_t *pix )
Q_strncpy( buffer + 18, comment, Q_strlen( comment )); Q_strncpy( buffer + 18, comment, Q_strlen( comment ));
out = buffer + 18 + Q_strlen( comment ); out = buffer + 18 + Q_strlen( comment );
// get image description
switch( pix->type )
{
case PF_RGB_24:
case PF_BGR_24: pixel_size = 3; break;
case PF_RGBA_32:
case PF_BGRA_32: pixel_size = 4; break;
default:
Mem_Free( buffer );
return false;
}
switch( pix->type ) switch( pix->type )
{ {
case PF_RGB_24: case PF_RGB_24:

Loading…
Cancel
Save