[poppler] poppler/poppler: FlateStream.cc, 1.2, 1.3 FlateStream.h, 1.2, 1.3

Jeff Muizelaar jrmuizel at kemper.freedesktop.org
Wed Sep 6 16:54:32 PDT 2006


Update of /cvs/poppler/poppler/poppler
In directory kemper:/tmp/cvs-serv15125/poppler

Modified Files:
	FlateStream.cc FlateStream.h 
Log Message:
2006-09-06  Jeff Muizelaar  <jeff at 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.


Index: FlateStream.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/FlateStream.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- FlateStream.cc	28 Aug 2005 03:22:04 -0000	1.2
+++ FlateStream.cc	6 Sep 2006 23:54:30 -0000	1.3
@@ -16,6 +16,7 @@
   }
   out_pos = 0;
   memset(&d_stream, 0, sizeof(d_stream));
+  inflateInit(&d_stream);
 }
 
 FlateStream::~FlateStream() {
@@ -27,9 +28,13 @@
 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::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;

Index: FlateStream.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/FlateStream.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- FlateStream.h	16 Sep 2005 18:29:18 -0000	1.2
+++ FlateStream.h	6 Sep 2006 23:54:30 -0000	1.3
@@ -57,7 +57,8 @@
   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;



More information about the poppler mailing list