From 4f20460b94053d10a464b565f772f07e93748e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BCnzli?= Date: Sun, 18 Aug 2013 13:12:45 +0200 Subject: optionally detect initial EOL in CCITTFaxDecode streams If /EndOfLine is set for a CCITTFaxDecode stream, the image must start with an EOL per the spec. Other readers seem to ignore all data up to the first EOL in that case - instead of rejecting such images as broken. Required for e.g. "1848 - 1d faxd doesn't start with EOL.pdf". --- source/fitz/filter-fax.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/fitz/filter-fax.c b/source/fitz/filter-fax.c index 8ac98f42..9ed5797a 100644 --- a/source/fitz/filter-fax.c +++ b/source/fitz/filter-fax.c @@ -311,6 +311,7 @@ typedef struct fz_faxd_s fz_faxd; enum { + STATE_INIT, /* initial state, optionally waiting for EOL */ STATE_NORMAL, /* neutral state, waiting for any code */ STATE_MAKEUP, /* got a 1d makeup code, waiting for terminating code */ STATE_EOL, /* at eol, needs output buffer space */ @@ -557,6 +558,22 @@ read_faxd(fz_stream *stm, unsigned char *buf, int len) unsigned char *ep = buf + len; unsigned char *tmp; + if (fax->stage == STATE_INIT && fax->end_of_line) + { + fill_bits(fax); + if ((fax->word >> (32 - 12)) != 1) + { + fz_warn(stm->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"); + } + + if (fax->stage == STATE_INIT) + fax->stage = STATE_NORMAL; + if (fax->stage == STATE_DONE) return 0; @@ -746,7 +763,7 @@ fz_open_faxd(fz_stream *chain, fax->bidx = 32; fax->word = 0; - fax->stage = STATE_NORMAL; + fax->stage = STATE_INIT; fax->a = -1; fax->c = 0; fax->dim = fax->k < 0 ? 2 : 1; -- cgit v1.2.3