diff options
author | Jeff Muizelaar <jeff@infidigm.net> | 2006-09-06 23:54:30 +0000 |
---|---|---|
committer | Jeff Muizelaar <jeff@infidigm.net> | 2006-09-06 23:54:30 +0000 |
commit | 3ea0aada0434c9f815814253dd9d1374ae6643cc (patch) | |
tree | 577df0199e60423bbd2420b9ac56926945d20f77 | |
parent | 1d2e6aedca0b8fcce6ac84ae2576ab067912886b (diff) |
2006-09-06 Jeff Muizelaar <jeff@infidigm.net>
* configure.ac:
* poppler/FlateStream.cc:
* poppler/FlateStream.h: Fix FlateStream to not read more than it
needs. This has a performance impact because our input buffer is now
only 1 byte large, however correctness is better than performance.
This should fix #3948.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | poppler/FlateStream.cc | 35 | ||||
-rw-r--r-- | poppler/FlateStream.h | 3 |
4 files changed, 37 insertions, 12 deletions
@@ -1,3 +1,12 @@ +2006-09-06 Jeff Muizelaar <jeff@infidigm.net> + + * configure.ac: + * poppler/FlateStream.cc: + * poppler/FlateStream.h: Fix FlateStream to not read more than it + needs. This has a performance impact because our input buffer is now + only 1 byte large, however correctness is better than performance. + This should fix #3948. + 2006-09-04 Jeff Muizelaar <jeff@infidigm.net> * poppler/CairoOutputDev.cc: Initialize currentFont to NULL before diff --git a/configure.ac b/configure.ac index c57daeed..de197b70 100644 --- a/configure.ac +++ b/configure.ac @@ -82,7 +82,7 @@ fi dnl Test for zlib AC_ARG_ENABLE(zlib, AC_HELP_STRING([--disable-zlib], - [Don't build against zlib. This is the default value as the zlib code is known to fail in some cases.]), + [Don't build against zlib.]), enable_zlib=$enableval, enable_zlib="no") if test x$enable_zlib = xyes; then diff --git a/poppler/FlateStream.cc b/poppler/FlateStream.cc index 67fa6c3c..da17c685 100644 --- a/poppler/FlateStream.cc +++ b/poppler/FlateStream.cc @@ -16,6 +16,7 @@ FlateStream::FlateStream(Stream *strA, int predictor, int columns, int colors, i } out_pos = 0; memset(&d_stream, 0, sizeof(d_stream)); + inflateInit(&d_stream); } FlateStream::~FlateStream() { @@ -27,9 +28,13 @@ FlateStream::~FlateStream() { void FlateStream::reset() { //FIXME: what are the semantics of reset? //i.e. how much intialization has to happen in the constructor? - str->reset(); + + /* reinitialize zlib */ + inflateEnd(&d_stream); memset(&d_stream, 0, sizeof(d_stream)); inflateInit(&d_stream); + + str->reset(); d_stream.avail_in = 0; status = Z_OK; out_pos = 0; @@ -61,25 +66,35 @@ int FlateStream::lookChar() { } int FlateStream::fill_buffer() { + /* only fill the buffer if it has all been used */ if (out_pos >= out_buf_len) { + /* check if the flatestream has been exhausted */ if (status == Z_STREAM_END) { return -1; } + + /* set to the begining of out_buf */ d_stream.avail_out = sizeof(out_buf); d_stream.next_out = out_buf; out_pos = 0; - /* buffer is empty so we need to fill it */ - if (d_stream.avail_in == 0) { - int c; - /* read from the source stream */ - while (d_stream.avail_in < sizeof(in_buf) && (c = str->getChar()) != EOF) { - in_buf[d_stream.avail_in++] = c; + + while (1) { + /* buffer is empty so we need to fill it */ + if (d_stream.avail_in == 0) { + int c; + /* read from the source stream */ + while (d_stream.avail_in < sizeof(in_buf) && (c = str->getChar()) != EOF) { + in_buf[d_stream.avail_in++] = c; + } + d_stream.next_in = in_buf; } - d_stream.next_in = in_buf; - } - while (d_stream.avail_out && d_stream.avail_in && (status == Z_OK || status == Z_BUF_ERROR)) { + + /* keep decompressing until we can't anymore */ + if (d_stream.avail_out == 0 || d_stream.avail_in == 0 || (status != Z_OK && status != Z_BUF_ERROR)) + break; status = inflate(&d_stream, Z_SYNC_FLUSH); } + out_buf_len = sizeof(out_buf) - d_stream.avail_out; if (status != Z_OK && status != Z_STREAM_END) return -1; diff --git a/poppler/FlateStream.h b/poppler/FlateStream.h index 82021341..812c6292 100644 --- a/poppler/FlateStream.h +++ b/poppler/FlateStream.h @@ -57,7 +57,8 @@ private: z_stream d_stream; StreamPredictor *pred; int status; - unsigned char in_buf[4096]; + /* in_buf currently needs to be 1 or we over read from EmbedStreams */ + unsigned char in_buf[1]; unsigned char out_buf[4096]; int out_pos; int out_buf_len; |