[poppler] poppler/poppler: JBIG2Stream.cc,1.7,1.8

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Apr 5 11:20:58 PDT 2006


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

Modified Files:
	JBIG2Stream.cc 
Log Message:
poppler/JBIG2Stream.cc: Fix for some buggy JBIG2 documents, patch by Raj Kumar and Paul Walmsley. Fixes bug 6500


Index: JBIG2Stream.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/JBIG2Stream.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- JBIG2Stream.cc	28 Feb 2006 19:59:58 -0000	1.7
+++ JBIG2Stream.cc	5 Apr 2006 18:20:56 -0000	1.8
@@ -1229,6 +1229,7 @@
   Guint segNum, segFlags, segType, page, segLength;
   Guint refFlags, nRefSegs;
   Guint *refSegs;
+  int segDataPos;
   int c1, c2, c3;
   Guint i;
 
@@ -1296,6 +1297,9 @@
       goto eofError2;
     }
 
+    // keep track of the start of the segment data 
+    segDataPos = getPos();
+
     // read the segment data
     switch (segType) {
     case 0:
@@ -1373,6 +1377,45 @@
       break;
     }
 
+    // Make sure the segment handler read all of the bytes in the 
+    // segment data, unless this segment is marked as having an
+    // unknown length (section 7.2.7 of the JBIG2 Final Committee Draft)
+
+    if (segLength != 0xffffffff) {
+
+      int segExtraBytes = segDataPos + segLength - getPos();
+      if (segExtraBytes > 0) {
+
+	// If we didn't read all of the bytes in the segment data,
+	// indicate an error, and throw away the rest of the data.
+	
+	// v.3.1.01.13 of the LuraTech PDF Compressor Server will
+	// sometimes generate an extraneous NULL byte at the end of
+	// arithmetic-coded symbol dictionary segments when numNewSyms
+	// == 0.  Segments like this often occur for blank pages.
+	
+	error(getPos(), "%d extraneous byte%s after segment",
+	      segExtraBytes, (segExtraBytes > 1) ? "s" : "");
+	
+	// Burn through the remaining bytes -- inefficient, but
+	// hopefully we're not doing this much
+	
+	int trash;
+	for (int i = segExtraBytes; i > 0; i--) {
+	  readByte(&trash);
+	}
+	
+      } else if (segExtraBytes < 0) {
+	
+	// If we read more bytes than we should have, according to the 
+	// segment length field, note an error.
+	
+	error(getPos(), "Previous segment handler read too many bytes");
+	
+      }
+
+    }
+    
     gfree(refSegs);
   }
 



More information about the poppler mailing list