[poppler] poppler/poppler: DCTStream.cc,1.1,1.2

Albert Astals Cid aacid at freedesktop.org
Tue Jul 26 06:40:39 EST 2005


Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv11208/poppler

Modified Files:
	DCTStream.cc 
Log Message:
Work on bad jpeg data that have garbage before the start marker. Fixes bug #3299


Index: DCTStream.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/DCTStream.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DCTStream.cc	11 Mar 2005 21:43:16 -0000	1.1
+++ DCTStream.cc	25 Jul 2005 20:40:37 -0000	1.2
@@ -64,6 +64,44 @@
   int row_stride;
 
   str->reset();
+  
+  // JPEG data has to start with 0xFF 0xD8
+  // but some pdf like the one on 
+  // https://bugs.freedesktop.org/show_bug.cgi?id=3299
+  // does have some garbage before that this seeks for
+  // the start marker...
+  bool startFound = false;
+  int c = 0, c2 = 0;
+  int n = 0;
+  while (!startFound)
+  {
+    if (!c)
+    {
+      c = str->getChar();
+      if (c != 0xFF) c = 0;
+      if (c == -1)
+      {
+        error(-1, "Could not find start of jpeg data");
+        exit(1);
+      }
+    }
+    else
+    {
+      c2 = str->getChar();
+      if (c2 != 0xD8)
+      {
+        c = 0;
+        c2 = 0;
+      }
+      else startFound = true;
+    }
+    n++;
+  }
+
+  // ...and this skips the garbage
+  str->reset();
+  for (n = n - 2; n > 0; n--) str->getChar();
+  
   jpeg_read_header(&cinfo, TRUE);
   jpeg_start_decompress(&cinfo);
 



More information about the poppler mailing list