aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Flate.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-07-29 18:07:19 +0200
committerJay Berkenbilt <ejb@ql.org>2017-07-29 18:19:04 +0200
commit6a7d53ad2bc9c7eb5964b5c0424616e8b3f068cd (patch)
treeedc61faa65a5f967e4dc229549b407eff65f99ad /libqpdf/Pl_Flate.cc
parent07d6f770b2a1c731cdf4f981ddc01466dbbc4ba0 (diff)
downloadqpdf-6a7d53ad2bc9c7eb5964b5c0424616e8b3f068cd.tar.zst
Handle zlib data errors better (fixes #106)
Diffstat (limited to 'libqpdf/Pl_Flate.cc')
-rw-r--r--libqpdf/Pl_Flate.cc50
1 files changed, 29 insertions, 21 deletions
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index 297cdac7..535383c9 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -157,28 +157,36 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush)
void
Pl_Flate::finish()
{
- if (this->outbuf)
+ try
{
- if (this->initialized)
- {
- z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
- unsigned char buf[1];
- buf[0] = '\0';
- handleData(buf, 0, Z_FINISH);
- int err = Z_OK;
- if (action == a_deflate)
- {
- err = deflateEnd(&zstream);
- }
- else
- {
- err = inflateEnd(&zstream);
- }
- checkError("End", err);
- }
-
- delete [] this->outbuf;
- this->outbuf = 0;
+ if (this->outbuf)
+ {
+ if (this->initialized)
+ {
+ z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
+ unsigned char buf[1];
+ buf[0] = '\0';
+ handleData(buf, 0, Z_FINISH);
+ int err = Z_OK;
+ if (action == a_deflate)
+ {
+ err = deflateEnd(&zstream);
+ }
+ else
+ {
+ err = inflateEnd(&zstream);
+ }
+ checkError("End", err);
+ }
+
+ delete [] this->outbuf;
+ this->outbuf = 0;
+ }
+ }
+ catch (std::exception& e)
+ {
+ this->getNext()->finish();
+ throw e;
}
this->getNext()->finish();
}