From 5d4cad9c02e9d4f31477fed0e3b20b35c83936f8 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 20 Jun 2012 11:20:57 -0400 Subject: ABI change: fix use of off_t, size_t, and integer types Significantly improve the code's use of off_t for file offsets, size_t for memory sizes, and integer types in cases where there has to be compatibility with external interfaces. Rework sections of the code that would have prevented qpdf from working on files larger than 2 (or maybe 4) GB in size. --- libqpdf/Pl_Flate.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libqpdf/Pl_Flate.cc') diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index d166e9ab..30616707 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -40,7 +40,7 @@ Pl_Flate::~Pl_Flate() } void -Pl_Flate::write(unsigned char* data, int len) +Pl_Flate::write(unsigned char* data, size_t len) { if (this->outbuf == 0) { @@ -48,7 +48,19 @@ Pl_Flate::write(unsigned char* data, int len) this->identifier + ": Pl_Flate: write() called after finish() called"); } - handleData(data, len, Z_NO_FLUSH); + + // Write in chunks in case len is too big to fit in an int. + // Assume int is at least 32 bits. + static size_t const max_bytes = 1 << 30; + size_t bytes_left = len; + unsigned char* buf = data; + while (bytes_left > 0) + { + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); + handleData(buf, (int)bytes, Z_NO_FLUSH); + bytes_left -= bytes; + buf += bytes; + } } void -- cgit v1.2.3-54-g00ecf