Browse Source

engine: imagelib: img_png: validate image size through common engine function

pull/2/head
Alibek Omarov 2 years ago
parent
commit
e48b708fa6
  1. 1
      common/com_image.h
  2. 9
      engine/common/imagelib/img_png.c

1
common/com_image.h

@ -49,6 +49,7 @@ typedef enum
IL_DDS_HARDWARE = BIT(4), // DXT compression is support IL_DDS_HARDWARE = BIT(4), // DXT compression is support
IL_LOAD_DECAL = BIT(5), // special mode for load gradient decals IL_LOAD_DECAL = BIT(5), // special mode for load gradient decals
IL_OVERVIEW = BIT(6), // overview required some unque operations IL_OVERVIEW = BIT(6), // overview required some unque operations
IL_LOAD_PLAYER_DECAL = BIT(7), // special mode for player decals
} ilFlags_t; } ilFlags_t;
// goes into rgbdata_t->encode // goes into rgbdata_t->encode

9
engine/common/imagelib/img_png.c

@ -82,8 +82,8 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
} }
// convert image width and height to little endian // convert image width and height to little endian
png_hdr.ihdr_chunk.height = ntohl( png_hdr.ihdr_chunk.height ); image.height = png_hdr.ihdr_chunk.height = ntohl( png_hdr.ihdr_chunk.height );
png_hdr.ihdr_chunk.width = ntohl( png_hdr.ihdr_chunk.width ); image.width = png_hdr.ihdr_chunk.width = ntohl( png_hdr.ihdr_chunk.width );
if( png_hdr.ihdr_chunk.height == 0 || png_hdr.ihdr_chunk.width == 0 ) if( png_hdr.ihdr_chunk.height == 0 || png_hdr.ihdr_chunk.width == 0 )
{ {
@ -91,6 +91,9 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
return false; return false;
} }
if( !Image_ValidSize( name ))
return false;
if( png_hdr.ihdr_chunk.bitdepth != 8 ) if( png_hdr.ihdr_chunk.bitdepth != 8 )
{ {
Con_DPrintf( S_WARN "Image_LoadPNG: Only 8-bit images is supported (%s)\n", name ); Con_DPrintf( S_WARN "Image_LoadPNG: Only 8-bit images is supported (%s)\n", name );
@ -261,8 +264,6 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
} }
image.type = PF_RGBA_32; // always exctracted to 32-bit buffer image.type = PF_RGBA_32; // always exctracted to 32-bit buffer
image.width = png_hdr.ihdr_chunk.width;
image.height = png_hdr.ihdr_chunk.height;
pixel_count = image.height * image.width; pixel_count = image.height * image.width;
image.size = pixel_count * 4; image.size = pixel_count * 4;

Loading…
Cancel
Save