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];
JPEGReadContext ctx;
if (data == NULL || data_size == 0 || pic == NULL) return 0;
(void)keep_alpha;
memset(&ctx, 0, sizeof(ctx));
ctx.data = data;

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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,