diff options
author | Simon Bünzli <zeniko@gmail.com> | 2013-09-27 17:00:15 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-09-27 17:09:49 +0100 |
commit | 049839fcef1ff37b91e3b1adb669d42e6c1a3843 (patch) | |
tree | c9d7ae21dfe97eb6cc0f2511419a7e2d192b039f /source/fitz | |
parent | c301f0b3b493935fcf1d7ff58543486b7c6b2773 (diff) | |
download | mupdf-049839fcef1ff37b91e3b1adb669d42e6c1a3843.tar.xz |
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.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/filter-fax.c | 37 |
1 files changed, 33 insertions, 4 deletions
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; |