all repos — mgba @ a903fe19d8ae9eff97c25f2595f17e0ed5d6bc34

mGBA Game Boy Advance Emulator

Util: Add PNGRead safety checks
Vicki Pfau vi@endrift.com
Thu, 25 Jun 2020 01:54:33 -0700
commit

a903fe19d8ae9eff97c25f2595f17e0ed5d6bc34

parent

fbce061806e5e5bd19ac6bb1a90d5387c3a7747d

1 files changed, 12 insertions(+), 0 deletions(-)

jump to
M src/util/png-io.csrc/util/png-io.c

@@ -273,6 +273,10 @@ return true;

} bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride) { + if (png_get_channels(png, info) != 3) { + return false; + } + if (setjmp(png_jmpbuf(png))) { return false; }

@@ -324,6 +328,10 @@ return true;

} bool PNGReadPixelsA(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride) { + if (png_get_channels(png, info) != 4) { + return false; + } + if (setjmp(png_jmpbuf(png))) { return false; }

@@ -375,6 +383,10 @@ return true;

} bool PNGReadPixels8(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride) { + if (png_get_channels(png, info) != 1) { + return false; + } + if (setjmp(png_jmpbuf(png))) { return false; }