summaryrefslogtreecommitdiff
path: root/source/fitz/load-png.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2018-01-31 18:31:07 +0100
committerSebastian Rasmussen <sebras@gmail.com>2018-02-01 17:21:16 +0100
commit4ccc9cdc72346175fd22aafbce03847f1e287d26 (patch)
tree6e6c81d3d4b38ff10cc7ea4f51301cb9b41beeca /source/fitz/load-png.c
parentaa188d02031df0c96e785d4ea0ef0f95599827d1 (diff)
downloadmupdf-4ccc9cdc72346175fd22aafbce03847f1e287d26.tar.xz
Drop JPEG/J2K/JPEG-XR/PNG/TIFF colorspaces even upon exception.
For TIFF it was not just the colorspace, but other data as well.
Diffstat (limited to 'source/fitz/load-png.c')
-rw-r--r--source/fitz/load-png.c21
1 files changed, 15 insertions, 6 deletions
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;