summaryrefslogtreecommitdiff
path: root/source/fitz/compressed-buffer.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-03-30 14:19:34 +0100
committerRobin Watts <robin.watts@artifex.com>2015-03-30 17:33:22 +0100
commit12dc2a8a678d0476ba692cd758f2b8164cf8e541 (patch)
tree0da64236ec841b6ad0dd48b2498138ca4dd03a20 /source/fitz/compressed-buffer.c
parentc6e63f40cdf49dbeac105ba9dcfa74643a8a1332 (diff)
downloadmupdf-12dc2a8a678d0476ba692cd758f2b8164cf8e541.tar.xz
Bug 695549: Avoid returning compressed buffer as uncompressed.
pdf_load_image_stream is supposed to return a buffer containing the uncompressed stream from an object (or, in the case of image streams where an fz_compression_params structure is supplied, a stream decompressed up to the point of the image format compression). We have an optimisation in pdf_load_image_stream to allow it to return the existing buffer from a cached object rather than reloading it again, but as bug 695549 points out, this breaks in the case where the cached stream is compressed. The suggested fix by the bug reporter (Stefan Klein) would work in that it would stop compressed streams being returned as uncompressed ones, but it is not perfect as it could lead to several copies of shortstoppable image streams being loaded (and for streams with null or empty array filters being mistaken for compressed ones). The fix here solves these cases too.
Diffstat (limited to 'source/fitz/compressed-buffer.c')
-rw-r--r--source/fitz/compressed-buffer.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c
index 85890c72..d1c73351 100644
--- a/source/fitz/compressed-buffer.c
+++ b/source/fitz/compressed-buffer.c
@@ -27,7 +27,8 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *chain, fz_compression_pa
switch (params->type)
{
case FZ_IMAGE_FAX:
- *l2factor = 0;
+ if (l2factor)
+ *l2factor = 0;
return fz_open_faxd(ctx, chain,
params->u.fax.k,
params->u.fax.end_of_line,
@@ -37,26 +38,30 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *chain, fz_compression_pa
params->u.fax.end_of_block,
params->u.fax.black_is_1);
case FZ_IMAGE_JPEG:
- if (*l2factor > 3)
+ if (l2factor && *l2factor > 3)
*l2factor = 3;
- return fz_open_dctd(ctx, chain, params->u.jpeg.color_transform, *l2factor, NULL);
+ return fz_open_dctd(ctx, chain, params->u.jpeg.color_transform, l2factor ? *l2factor : 0, NULL);
case FZ_IMAGE_RLD:
- *l2factor = 0;
+ if (l2factor)
+ *l2factor = 0;
return fz_open_rld(ctx, chain);
case FZ_IMAGE_FLATE:
- *l2factor = 0;
+ if (l2factor)
+ *l2factor = 0;
chain = fz_open_flated(ctx, chain, 15);
if (params->u.flate.predictor > 1)
chain = fz_open_predict(ctx, chain, params->u.flate.predictor, params->u.flate.columns, params->u.flate.colors, params->u.flate.bpc);
return chain;
case FZ_IMAGE_LZW:
- *l2factor = 0;
+ if (l2factor)
+ *l2factor = 0;
chain = fz_open_lzwd(ctx, chain, params->u.lzw.early_change);
if (params->u.lzw.predictor > 1)
chain = fz_open_predict(ctx, chain, params->u.lzw.predictor, params->u.lzw.columns, params->u.lzw.colors, params->u.lzw.bpc);
return chain;
default:
- *l2factor = 0;
+ if (l2factor)
+ *l2factor = 0;
break;
}