From 049839fcef1ff37b91e3b1adb669d42e6c1a3843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BCnzli?= Date: Fri, 27 Sep 2013 17:00:15 +0200 Subject: fix bug 694573 Currently, MuPDF throws away entire CCITT encoded images whenever an error happens in the code stream. Other PDF readers seem to rather render what has been decoded up to the point of the error. This patch enables such behavior for MuPDF as well. --- source/fitz/filter-fax.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'source/fitz') diff --git a/source/fitz/filter-fax.c b/source/fitz/filter-fax.c index 9ed5797a..38f948bf 100644 --- a/source/fitz/filter-fax.c +++ b/source/fitz/filter-fax.c @@ -553,6 +553,7 @@ dec2d(fz_context *ctx, fz_faxd *fax) static int read_faxd(fz_stream *stm, unsigned char *buf, int len) { + fz_context *ctx = stm->ctx; fz_faxd *fax = stm->state; unsigned char *p = buf; unsigned char *ep = buf + len; @@ -563,12 +564,12 @@ read_faxd(fz_stream *stm, unsigned char *buf, int len) fill_bits(fax); if ((fax->word >> (32 - 12)) != 1) { - fz_warn(stm->ctx, "faxd stream doesn't start with EOL"); + fz_warn(ctx, "faxd stream doesn't start with EOL"); while (!fill_bits(fax) && (fax->word >> (32 - 12)) != 1) eat_bits(fax, 1); } if ((fax->word >> (32 - 12)) != 1) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "initial EOL not found"); + fz_throw(ctx, FZ_ERROR_GENERIC, "initial EOL not found"); } if (fax->stage == STATE_INIT) @@ -626,12 +627,26 @@ loop: else if (fax->dim == 1) { fax->eolc = 0; - dec1d(stm->ctx, fax); + fz_try(ctx) + { + dec1d(ctx, fax); + } + fz_catch(ctx) + { + goto error; + } } else if (fax->dim == 2) { fax->eolc = 0; - dec2d(stm->ctx, fax); + fz_try(ctx) + { + dec2d(ctx, fax); + } + fz_catch(ctx) + { + goto error; + } } /* no eol check after makeup codes nor in the middle of an H code */ @@ -709,6 +724,20 @@ eol: goto loop; +error: + /* decode the remaining pixels up to where the error occurred */ + if (fax->black_is_1) + { + while (fax->rp < fax->wp && p < ep) + *p++ = *fax->rp++; + } + else + { + while (fax->rp < fax->wp && p < ep) + *p++ = *fax->rp++ ^ 0xff; + } + /* fallthrough */ + rtc: fax->stage = STATE_DONE; return p - buf; -- cgit v1.2.3