imageio/*dec,Read*: add input parameter checks

Change-Id: I5e069d6ea4da9d8c71be03ef99aad679dd1aad21
This commit is contained in:
James Zern 2016-10-13 03:43:50 +00:00
parent 4eb5df28d1
commit 2a2773ea29
5 changed files with 14 additions and 3 deletions

View File

@ -266,6 +266,8 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
JSAMPROW buffer[1]; JSAMPROW buffer[1];
JPEGReadContext ctx; JPEGReadContext ctx;
if (data == NULL || data_size == 0 || pic == NULL) return 0;
(void)keep_alpha; (void)keep_alpha;
memset(&ctx, 0, sizeof(ctx)); memset(&ctx, 0, sizeof(ctx));
ctx.data = data; ctx.data = data;

View File

@ -220,6 +220,8 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
int64_t stride; int64_t stride;
uint8_t* volatile rgb = NULL; uint8_t* volatile rgb = NULL;
if (data == NULL || data_size == 0 || pic == NULL) return 0;
context.data = data; context.data = data;
context.data_size = data_size; context.data_size = data_size;

View File

@ -120,15 +120,18 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
WebPPicture* const pic, int keep_alpha, WebPPicture* const pic, int keep_alpha,
Metadata* const metadata) { Metadata* const metadata) {
MyData my_data = { data, (toff_t)data_size, 0 }; MyData my_data = { data, (toff_t)data_size, 0 };
TIFF* const tif = TIFFClientOpen("Memory", "r", &my_data, TIFF* tif;
MyRead, MyRead, MySeek, MyClose,
MySize, MyMapFile, MyUnmapFile);
uint32 width, height; uint32 width, height;
uint32* raster; uint32* raster;
int64_t alloc_size; int64_t alloc_size;
int ok = 0; int ok = 0;
tdir_t dircount; 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) { if (tif == NULL) {
fprintf(stderr, "Error! Cannot parse TIFF file\n"); fprintf(stderr, "Error! Cannot parse TIFF file\n");
return 0; return 0;

View File

@ -143,6 +143,8 @@ int ReadWebP(const uint8_t* const data, size_t data_size,
WebPDecBuffer* const output_buffer = &config.output; WebPDecBuffer* const output_buffer = &config.output;
WebPBitstreamFeatures* const bitstream = &config.input; WebPBitstreamFeatures* const bitstream = &config.input;
if (data == NULL || data_size == 0 || pic == NULL) return 0;
// TODO(jzern): add Exif/XMP/ICC extraction. // TODO(jzern): add Exif/XMP/ICC extraction.
if (metadata != NULL) { if (metadata != NULL) {
fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n"); fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n");

View File

@ -276,6 +276,8 @@ int ReadPictureWithWIC(const char* const filename,
int has_alpha = 0; int has_alpha = 0;
int64_t stride; int64_t stride;
if (filename == NULL || pic == NULL) return 0;
IFS(CoInitialize(NULL)); IFS(CoInitialize(NULL));
IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL, IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,