summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSimon Bünzli <zeniko@gmail.com>2013-08-18 13:12:45 +0200
committerRobin Watts <robin.watts@artifex.com>2013-08-28 13:35:49 +0100
commit4f20460b94053d10a464b565f772f07e93748e24 (patch)
treeae2de59a165437730b3af70aa37a333f1044be13 /source
parent01acc82dc88fe43c4743bc18dce4e8581f129d31 (diff)
downloadmupdf-4f20460b94053d10a464b565f772f07e93748e24.tar.xz
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".
Diffstat (limited to 'source')
-rw-r--r--source/fitz/filter-fax.c19
1 files changed, 18 insertions, 1 deletions
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;