2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-31 01:10:51 +00:00

Ignore zlib data check errors (fixes #191)

This commit is contained in:
Jay Berkenbilt 2018-03-03 11:35:01 -05:00
parent fa76d817c6
commit 7b9f23a99a
3 changed files with 17 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2018-03-03 Jay Berkenbilt <ejb@ql.org>
* Ignore zlib data check errors while uncompressing streams. This
is consistent with behaviors of other readers and enables handling
of some incorrectly written zlib strems. Fixes #191.
2018-02-25 Jay Berkenbilt <ejb@ql.org> 2018-02-25 Jay Berkenbilt <ejb@ql.org>
* 8.0.0: release * 8.0.0: release

View File

@ -1,5 +1,6 @@
#include <qpdf/Pl_Flate.hh> #include <qpdf/Pl_Flate.hh>
#include <zlib.h> #include <zlib.h>
#include <string.h>
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
@ -71,7 +72,8 @@ Pl_Flate::write(unsigned char* data, size_t len)
while (bytes_left > 0) while (bytes_left > 0)
{ {
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
handleData(buf, bytes, Z_NO_FLUSH); handleData(buf, bytes,
(action == a_inflate ? Z_SYNC_FLUSH : Z_NO_FLUSH));
bytes_left -= bytes; bytes_left -= bytes;
buf += bytes; buf += bytes;
} }
@ -125,6 +127,14 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush)
{ {
err = inflate(&zstream, flush); err = inflate(&zstream, flush);
} }
if ((action == a_inflate) && (err != Z_OK) && zstream.msg &&
(strcmp(zstream.msg, "incorrect data check") == 0))
{
// Other PDF readers ignore this specific error. Combining
// this with Z_SYNC_FLUSH enables qpdf to handle some
// broken zlib streams without losing data.
err = Z_STREAM_END;
}
switch (err) switch (err)
{ {
case Z_BUF_ERROR: case Z_BUF_ERROR:

View File

@ -1,6 +1,4 @@
WARNING: issue-106.pdf: file is damaged WARNING: issue-106.pdf: file is damaged
WARNING: issue-106.pdf (offset 809): xref not found WARNING: issue-106.pdf (offset 809): xref not found
WARNING: issue-106.pdf: Attempting to reconstruct cross-reference table WARNING: issue-106.pdf: Attempting to reconstruct cross-reference table
WARNING: issue-106.pdf (offset 965): error decoding stream data for object 8 0: stream inflate: inflate: data: incorrect data check
WARNING: issue-106.pdf (offset 965): stream will be re-processed without filtering to avoid data loss
qpdf: operation succeeded with warnings; resulting file may have some problems qpdf: operation succeeded with warnings; resulting file may have some problems