X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fpcx.c;h=1c63396a5f04751d8da4f029c6c82366c9597cb7;hp=514d30de6041f7683a86e96cffed79e474767357;hb=afd9659572a8963b24b17340613b396ea49cbe55;hpb=7904f4290f1604d66285a5cd7bdf82099557d74a diff --git a/src/pcx.c b/src/pcx.c index 514d30de..1c63396a 100644 --- a/src/pcx.c +++ b/src/pcx.c @@ -139,8 +139,9 @@ Image *Read_PCX_to_Image(char *filename) file_length = ftell(file); rewind(file); - if (file_length < PCX_HEADER_SIZE + PCX_COLORMAP_SIZE) + if (file_length < PCX_HEADER_SIZE) { + /* PCX file is too short to contain a valid PCX header */ fclose(file); return NULL; } @@ -185,6 +186,7 @@ Image *Read_PCX_to_Image(char *filename) filename, pcx.xmax, pcx.ymax, pcx.color_planes); printf("depth: %d\n", pcx.bits_per_pixel); + printf("color_planes: %d\n", pcx.color_planes); printf("bytes_per_line: %d\n", pcx.bytes_per_line); printf("palette type: %s\n", (pcx.palette_type == 1 ? "color" : @@ -205,6 +207,13 @@ Image *Read_PCX_to_Image(char *filename) return NULL; } + if (file_length < PCX_HEADER_SIZE + PCX_COLORMAP_SIZE) + { + /* PCX file is too short to contain a valid 256 colors colormap */ + fclose(file); + return NULL; + } + /* read colormap data */ if (!PCX_ReadColormap(image, buffer_ptr, buffer_last)) {