From d374ec148dda5934432112245716c8a207165c6c Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 22 Jan 2013 17:31:49 +0000 Subject: Bug 693527: Avoid JP2K images with themselves as their SMask. Bug 693527 points out that we fail to spot Jpeg 2000 images that have themselves as their own SMask and enter an infinite loop. We extend the code by passing the forcemask parameter in exactly the same way as the non-JPEG 2K code does. Thanks to Jarkko Poyry for spotting this, reporting it, and suggesting the fix. --- pdf/pdf_image.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pdf') diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index d71d974a..a756b648 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -9,7 +9,7 @@ struct pdf_image_key_s { int l2factor; }; -static void pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image); +static void pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image, int forcemask); static void pdf_mask_color_key(fz_pixmap *pix, int n, int *colorkey) @@ -328,7 +328,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c /* special case for JPEG2000 images */ if (pdf_is_jpx_image(ctx, dict)) { - pdf_load_jpx(xref, dict, image); + pdf_load_jpx(xref, dict, image, forcemask); if (forcemask) { @@ -494,7 +494,7 @@ pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict) } static void -pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) +pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image, int forcemask) { fz_buffer *buf = NULL; fz_colorspace *colorspace = NULL; @@ -530,7 +530,10 @@ pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) obj = pdf_dict_getsa(dict, "SMask", "Mask"); if (pdf_is_dict(obj)) { - image->base.mask = (fz_image *)pdf_load_image_imp(xref, NULL, obj, NULL, 1); + if (forcemask) + fz_warn(ctx, "Ignoring recursive JPX soft mask"); + else + image->base.mask = (fz_image *)pdf_load_image_imp(xref, NULL, obj, NULL, 1); } obj = pdf_dict_getsa(dict, "Decode", "D"); -- cgit v1.2.3