aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Flate.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-06-21 06:01:36 +0200
committerJay Berkenbilt <ejb@ql.org>2019-06-21 19:17:21 +0200
commitf40ffc9d6392edf9b6fe74d288d6d578e6d1a240 (patch)
treed4b406f61509fdf9cfc5802f9851f84805cf408d /libqpdf/Pl_Flate.cc
parentda30764bce31efc4e9a228a3554f291215e2055d (diff)
downloadqpdf-f40ffc9d6392edf9b6fe74d288d6d578e6d1a240.tar.zst
Pl_Flate: constructor's out_bufsize is now unsigned int
This is the type we need for the underlying zlib implementation.
Diffstat (limited to 'libqpdf/Pl_Flate.cc')
-rw-r--r--libqpdf/Pl_Flate.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index 4cd48046..67e02d2d 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -1,13 +1,15 @@
#include <qpdf/Pl_Flate.hh>
#include <zlib.h>
#include <string.h>
+#include <limits.h>
#include <qpdf/QUtil.hh>
+#include <qpdf/QIntC.hh>
Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
- action_e action, int out_bufsize) :
+ action_e action, unsigned int out_bufsize_int) :
Pipeline(identifier, next),
- out_bufsize(out_bufsize),
+ out_bufsize(QIntC::to_size(out_bufsize_int)),
action(action),
initialized(false)
{
@@ -19,6 +21,13 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
// Windows environment.
this->zdata = new z_stream;
+ if (out_bufsize > UINT_MAX)
+ {
+ throw std::runtime_error(
+ "Pl_Flate: zlib doesn't support buffer"
+ " sizes larger than unsigned int");
+ }
+
z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
zstream.zalloc = 0;
zstream.zfree = 0;
@@ -26,7 +35,7 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
zstream.next_in = 0;
zstream.avail_in = 0;
zstream.next_out = this->outbuf;
- zstream.avail_out = out_bufsize;
+ zstream.avail_out = QIntC::to_uint(out_bufsize);
}
Pl_Flate::~Pl_Flate()
@@ -77,11 +86,17 @@ Pl_Flate::write(unsigned char* data, size_t len)
}
void
-Pl_Flate::handleData(unsigned char* data, int len, int flush)
+Pl_Flate::handleData(unsigned char* data, size_t len, int flush)
{
+ if (len > UINT_MAX)
+ {
+ throw std::runtime_error(
+ "Pl_Flate: zlib doesn't support data"
+ " blocks larger than int");
+ }
z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
zstream.next_in = data;
- zstream.avail_in = len;
+ zstream.avail_in = QIntC::to_uint(len);
if (! this->initialized)
{
@@ -156,12 +171,13 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush)
// needed, so we're done for now.
done = true;
}
- uLong ready = (this->out_bufsize - zstream.avail_out);
+ uLong ready =
+ QIntC::to_ulong(this->out_bufsize - zstream.avail_out);
if (ready > 0)
{
this->getNext()->write(this->outbuf, ready);
zstream.next_out = this->outbuf;
- zstream.avail_out = this->out_bufsize;
+ zstream.avail_out = QIntC::to_uint(this->out_bufsize);
}
}
break;