mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 20:04:31 +01:00
Add more sanity checks in png_load.
This commit is contained in:
1 parent
116edcb77a
commit
496ebf710a
2 files changed
+21
-5
No files matched your search
@@ -53,6 +53,13 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
|
||||
if (1 == pngLoadPtr((const unsigned char *)data, size, &width[0], &height[0], &image[0], false)) {
|
||||
*num_levels = 1;
|
||||
*fmt = Draw::DataFormat::R8G8B8A8_UNORM;
|
||||
if (!image[0]) {
|
||||
ELOG("WTF");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ELOG("PNG load failed");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -89,6 +96,10 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!image[0]) {
|
||||
Crash();
|
||||
}
|
||||
|
||||
if (num_levels < 0 || num_levels >= 16) {
|
||||
ELOG("Invalid num_levels: %d. Falling back to one. Image: %dx%d", num_levels, width[0], height[0]);
|
||||
num_levels = 1;
|
||||
|
||||
@@ -84,14 +84,12 @@ int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, in
|
||||
#else
|
||||
if (flip)
|
||||
ELOG("pngLoad: flip flag not supported, image will be loaded upside down");
|
||||
png_image png;
|
||||
memset(&png, 0, sizeof(png));
|
||||
png_image png{};
|
||||
png.version = PNG_IMAGE_VERSION;
|
||||
|
||||
png_image_begin_read_from_memory(&png, input_ptr, input_len);
|
||||
|
||||
if (PNG_IMAGE_FAILED(png))
|
||||
{
|
||||
if (PNG_IMAGE_FAILED(png)) {
|
||||
ELOG("pngLoad: %s", png.message);
|
||||
return 0;
|
||||
}
|
||||
@@ -100,7 +98,14 @@ int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, in
|
||||
png.format = PNG_FORMAT_RGBA;
|
||||
|
||||
int stride = PNG_IMAGE_ROW_STRIDE(png);
|
||||
*image_data_ptr = (unsigned char *)malloc(PNG_IMAGE_SIZE(png));
|
||||
|
||||
size_t size = PNG_IMAGE_SIZE(png);
|
||||
if (!size) {
|
||||
ELOG("pngLoad: empty image");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*image_data_ptr = (unsigned char *)malloc(size);
|
||||
png_image_finish_read(&png, NULL, *image_data_ptr, stride, NULL);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user