diff options
author | Krzysztof Kowalczyk <kkowalczyk@gmail.com> | 2008-04-21 03:30:46 +0200 |
---|---|---|
committer | Krzysztof Kowalczyk <kkowalczyk@gmail.com> | 2008-04-21 03:30:46 +0200 |
commit | bf4bd68a70bfe02c010082dcd603a137c3d6f1fb (patch) | |
tree | 75f4b4a4a799f0b4968047e0dae27c2288987bfa | |
parent | b4daccae9b21e16c0f2b0afa24569460cf1bc587 (diff) | |
download | mupdf-bf4bd68a70bfe02c010082dcd603a137c3d6f1fb.tar.xz |
don't treat truncated images as fatal (fixes truncated-image.pdf)"
-rw-r--r-- | mupdf/pdf_image.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/mupdf/pdf_image.c b/mupdf/pdf_image.c index 92bb2cea..32b7a52d 100644 --- a/mupdf/pdf_image.c +++ b/mupdf/pdf_image.c @@ -212,6 +212,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref) fz_colorspace *cs = nil; pdf_indexed *indexed = nil; int stride; + int realsize, expectedsize; if ((*imgp = pdf_finditem(xref->store, PDF_KIMAGE, ref))) { @@ -373,12 +374,26 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref) return error; } - if (img->samples->wp - img->samples->bp < stride * h) + expectedsize = stride *h; + realsize = img->samples->wp - img->samples->bp; + if (realsize < expectedsize) { - /* TODO: colorspace? */ + /* don't treat truncated image as fatal - get as much as possible and + fill the rest with 0 */ + fz_buffer *buf; + error = fz_newbuffer(&buf, expectedsize); + if (error) + { + /* TODO: colorspace? */ + fz_dropbuffer(img->samples); + fz_free(img); + return error; + } + memset(buf->bp, 0, expectedsize); + memmove(buf->bp, img->samples->bp, realsize); + buf->wp = buf->bp + expectedsize; fz_dropbuffer(img->samples); - fz_free(img); - return fz_throw("syntaxerror: truncated image data"); + img->samples = buf; } /* 0 means opaque and 1 means transparent, so we invert to get alpha */ |