From 4ccc9cdc72346175fd22aafbce03847f1e287d26 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 31 Jan 2018 18:31:07 +0100 Subject: Drop JPEG/J2K/JPEG-XR/PNG/TIFF colorspaces even upon exception. For TIFF it was not just the colorspace, but other data as well. --- source/fitz/load-png.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source/fitz/load-png.c') diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c index 179297a3..55dd8fe7 100644 --- a/source/fitz/load-png.c +++ b/source/fitz/load-png.c @@ -503,6 +503,7 @@ png_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_ { inflateEnd(&stm); fz_free(ctx, info->samples); + info->samples = NULL; } fz_rethrow(ctx); } @@ -513,6 +514,7 @@ png_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_ if (code != Z_OK) { fz_free(ctx, info->samples); + info->samples = NULL; fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm.msg); } @@ -527,6 +529,7 @@ png_read_image(fz_context *ctx, struct info *info, const unsigned char *p, size_ fz_catch(ctx) { fz_free(ctx, info->samples); + info->samples = NULL; fz_rethrow(ctx); } } @@ -614,13 +617,13 @@ fz_load_png(fz_context *ctx, const unsigned char *p, size_t total) fz_var(image); - png_read_image(ctx, &png, p, total, 0); - - stride = (png.width * png.n * png.depth + 7) / 8; - alpha = (png.n == 2 || png.n == 4 || png.transparency); - fz_try(ctx) { + png_read_image(ctx, &png, p, total, 0); + + stride = (png.width * png.n * png.depth + 7) / 8; + alpha = (png.n == 2 || png.n == 4 || png.transparency); + if (png.indexed) { image = fz_new_pixmap(ctx, NULL, png.width, png.height, NULL, 1); @@ -657,7 +660,13 @@ fz_load_png_info(fz_context *ctx, const unsigned char *p, size_t total, int *wp, { struct info png; - png_read_image(ctx, &png, p, total, 1); + fz_try(ctx) + png_read_image(ctx, &png, p, total, 1); + fz_catch(ctx) + { + fz_drop_colorspace(ctx, png.cs); + fz_rethrow(ctx); + } *cspacep = png.cs; *wp = png.width; -- cgit v1.2.3