aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Flate.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-03-03 17:35:01 +0100
committerJay Berkenbilt <ejb@ql.org>2018-03-03 17:35:01 +0100
commit7b9f23a99a1ea3e97eaecf80ef29e2805e351b8f (patch)
treedee043242db921c0e5b8e0b3f4decb4305800932 /libqpdf/Pl_Flate.cc
parentfa76d817c69173f8764cf0fa6240884d56023796 (diff)
downloadqpdf-7b9f23a99a1ea3e97eaecf80ef29e2805e351b8f.tar.zst
Ignore zlib data check errors (fixes #191)
Diffstat (limited to 'libqpdf/Pl_Flate.cc')
-rw-r--r--libqpdf/Pl_Flate.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index 212f7e1d..3becc135 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -1,5 +1,6 @@
#include <qpdf/Pl_Flate.hh>
#include <zlib.h>
+#include <string.h>
#include <qpdf/QUtil.hh>
@@ -71,7 +72,8 @@ Pl_Flate::write(unsigned char* data, size_t len)
while (bytes_left > 0)
{
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;
buf += bytes;
}
@@ -125,6 +127,14 @@ Pl_Flate::handleData(unsigned char* data, int len, int 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)
{
case Z_BUF_ERROR: