From 2a2773ea29568f67a3bc34842dd680964ed93df4 Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 13 Oct 2016 03:43:50 +0000 Subject: [PATCH] imageio/*dec,Read*: add input parameter checks Change-Id: I5e069d6ea4da9d8c71be03ef99aad679dd1aad21 --- imageio/jpegdec.c | 2 ++ imageio/pngdec.c | 2 ++ imageio/tiffdec.c | 9 ++++++--- imageio/webpdec.c | 2 ++ imageio/wicdec.c | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/imageio/jpegdec.c b/imageio/jpegdec.c index 315fb27c..632c6bb9 100644 --- a/imageio/jpegdec.c +++ b/imageio/jpegdec.c @@ -266,6 +266,8 @@ int ReadJPEG(const uint8_t* const data, size_t data_size, JSAMPROW buffer[1]; JPEGReadContext ctx; + if (data == NULL || data_size == 0 || pic == NULL) return 0; + (void)keep_alpha; memset(&ctx, 0, sizeof(ctx)); ctx.data = data; diff --git a/imageio/pngdec.c b/imageio/pngdec.c index 480210d1..f16c9ed5 100644 --- a/imageio/pngdec.c +++ b/imageio/pngdec.c @@ -220,6 +220,8 @@ int ReadPNG(const uint8_t* const data, size_t data_size, int64_t stride; uint8_t* volatile rgb = NULL; + if (data == NULL || data_size == 0 || pic == NULL) return 0; + context.data = data; context.data_size = data_size; diff --git a/imageio/tiffdec.c b/imageio/tiffdec.c index bfcccf85..7588e688 100644 --- a/imageio/tiffdec.c +++ b/imageio/tiffdec.c @@ -120,15 +120,18 @@ int ReadTIFF(const uint8_t* const data, size_t data_size, WebPPicture* const pic, int keep_alpha, Metadata* const metadata) { MyData my_data = { data, (toff_t)data_size, 0 }; - TIFF* const tif = TIFFClientOpen("Memory", "r", &my_data, - MyRead, MyRead, MySeek, MyClose, - MySize, MyMapFile, MyUnmapFile); + TIFF* tif; uint32 width, height; uint32* raster; int64_t alloc_size; int ok = 0; tdir_t dircount; + if (data == NULL || data_size == 0 || pic == NULL) return 0; + + tif = TIFFClientOpen("Memory", "r", &my_data, + MyRead, MyRead, MySeek, MyClose, + MySize, MyMapFile, MyUnmapFile); if (tif == NULL) { fprintf(stderr, "Error! Cannot parse TIFF file\n"); return 0; diff --git a/imageio/webpdec.c b/imageio/webpdec.c index 78a27b6f..3a725121 100644 --- a/imageio/webpdec.c +++ b/imageio/webpdec.c @@ -143,6 +143,8 @@ int ReadWebP(const uint8_t* const data, size_t data_size, WebPDecBuffer* const output_buffer = &config.output; WebPBitstreamFeatures* const bitstream = &config.input; + if (data == NULL || data_size == 0 || pic == NULL) return 0; + // TODO(jzern): add Exif/XMP/ICC extraction. if (metadata != NULL) { fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n"); diff --git a/imageio/wicdec.c b/imageio/wicdec.c index d0392494..3ee72a89 100644 --- a/imageio/wicdec.c +++ b/imageio/wicdec.c @@ -276,6 +276,8 @@ int ReadPictureWithWIC(const char* const filename, int has_alpha = 0; int64_t stride; + if (filename == NULL || pic == NULL) return 0; + IFS(CoInitialize(NULL)); IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL, CLSCTX_INPROC_SERVER,