Skip to content

Commit

Permalink
validate png size with actual psm
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito authored and Tupakaveli committed Jan 22, 2020
1 parent ddb0d97 commit f5ab840
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,10 @@ int texPngLoad(GSTEXTURE *texture, const char *path, int texId, short psm)
png_uint_32 pngWidth, pngHeight;
int bitDepth, colorType, interlaceType;
png_get_IHDR(pngPtr, infoPtr, &pngWidth, &pngHeight, &bitDepth, &colorType, &interlaceType, NULL, NULL);
if (texSizeValidate(pngWidth, pngHeight, psm) < 0)
return texPngEnd(pngPtr, infoPtr, file, ERR_BAD_DIMENSION);
texUpdate(texture, pngWidth, pngHeight);

if (bitDepth < 4)
png_set_packing(pngPtr);
if (colorType == PNG_COLOR_TYPE_GRAY)
png_set_expand(pngPtr);

if (bitDepth == 16)
png_set_strip_16(pngPtr);
Expand Down Expand Up @@ -512,6 +510,15 @@ int texPngLoad(GSTEXTURE *texture, const char *path, int texId, short psm)
return texPngEnd(pngPtr, infoPtr, file, ERR_BAD_DEPTH);
}

if (texSizeValidate(texture->Width, texture->Height, texture->PSM) < 0) {
if (texture->Clut) {
free(texture->Clut);
texture->Clut = NULL;
}

return texPngEnd(pngPtr, infoPtr, file, ERR_BAD_DIMENSION);
}

texPngReadData(texture, pngPtr, infoPtr, texPngReadPixels);

return texPngEnd(pngPtr, infoPtr, file, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ static void thmLoad(const char *themePath)
for (i = L1_ICON; i <= R3_ICON; i++)
thmLoadResource(&newT->textures[i], i, NULL, GS_PSM_CT32, 1); */

if (!themePath)
if (!themePath)
for (i = ELF_FORMAT; i <= VMODE_PAL; i++)
thmLoadResource(&newT->textures[i], i, NULL, GS_PSM_CT32, 1);

Expand Down

0 comments on commit f5ab840

Please sign in to comment.