summaryrefslogtreecommitdiff
path: root/source/fitz/filter-lzw.c
diff options
context:
space:
mode:
authorSimon Bünzli <zeniko@gmail.com>2014-12-18 12:29:31 +0100
committerSimon Bünzli <zeniko@gmail.com>2014-12-18 12:54:40 +0100
commitd3e295b507a1af10e066d72c386095f9bd8a8623 (patch)
tree497647d6bdf9799323adcca20aa89af1ff4e6792 /source/fitz/filter-lzw.c
parent064e998fb4fbf3cb41f743db246bd641a74ea0ba (diff)
downloadmupdf-d3e295b507a1af10e066d72c386095f9bd8a8623.tar.xz
Bug 695746: make LZW decoder slightly more tolerant
Ghostscript's LZW decoder accepts invalid LZW code 4096 if it's immediately followed by LZW clear code 256 for handling files produced by certain broken encoders and other common PDF readers seem to have similar error handling. This patch makes MuPDF tolerate such broken files as well.
Diffstat (limited to 'source/fitz/filter-lzw.c')
-rw-r--r--source/fitz/filter-lzw.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/source/fitz/filter-lzw.c b/source/fitz/filter-lzw.c
index e13b0ef0..16b5253a 100644
--- a/source/fitz/filter-lzw.c
+++ b/source/fitz/filter-lzw.c
@@ -87,7 +87,7 @@ next_lzwd(fz_stream *stm, int len)
break;
}
- if (next_code >= NUM_CODES && code != LZW_CLEAR)
+ if (next_code > NUM_CODES && code != LZW_CLEAR)
{
fz_warn(stm->ctx, "missing clear code in lzw decode");
code = LZW_CLEAR;
@@ -106,6 +106,12 @@ next_lzwd(fz_stream *stm, int len)
{
old_code = code;
}
+ else if (next_code == NUM_CODES)
+ {
+ /* TODO: Ghostscript checks for a following LZW_CLEAR before tolerating */
+ fz_warn(stm->ctx, "tolerating a single out of range code in lzw decode");
+ next_code++;
+ }
else if (code > next_code || next_code >= NUM_CODES)
{
fz_warn(stm->ctx, "out of range code encountered in lzw decode");