Util: Add PNGRead safety checks
Vicki Pfau vi@endrift.com
Thu, 25 Jun 2020 01:54:33 -0700
1 files changed,
12 insertions(+),
0 deletions(-)
jump to
M
src/util/png-io.c
→
src/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; }