* poppler/JBIG2Stream.cc:
        * poppler/Stream.cc: Patch by Derek B. Noonburg <derekn@foolabs.com>
        to fix some errors in CCITTFaxStream and JBIG2Stream.cc
diff --git a/ChangeLog b/ChangeLog
index 73af24f..b3e416c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-09-03  Albert Astals Cid <aacid@kde.org>
+
+	* poppler/JBIG2Stream.cc:
+	* poppler/Stream.cc: Patch by Derek B. Noonburg <derekn@foolabs.com>
+	to fix some errors in CCITTFaxStream and JBIG2Stream.cc
+
 2007-09-03  Carlos Garcia Campos  <carlosgc@gnome.org>
 
 	* gtk-doc.make:
diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index 5c66113..d1eb99b 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -507,7 +507,7 @@
     ++nBytesRead;
   }
   while (1) {
-    if (bufLen >= 7 && ((buf >> (bufLen - 7)) & 0x7f) == 0) {
+    if (bufLen >= 11 && ((buf >> (bufLen - 7)) & 0x7f) == 0) {
       if (bufLen <= 12) {
 	code = buf << (12 - bufLen);
       } else {
@@ -550,14 +550,15 @@
     ++nBytesRead;
   }
   while (1) {
-    if (bufLen >= 6 && ((buf >> (bufLen - 6)) & 0x3f) == 0) {
+    if (bufLen >= 10 && ((buf >> (bufLen - 6)) & 0x3f) == 0) {
       if (bufLen <= 13) {
 	code = buf << (13 - bufLen);
       } else {
 	code = buf >> (bufLen - 13);
       }
       p = &blackTab1[code & 0x7f];
-    } else if (bufLen >= 4 && ((buf >> (bufLen - 4)) & 0x0f) == 0) {
+    } else if (bufLen >= 7 && ((buf >> (bufLen - 4)) & 0x0f) == 0 &&
+	       ((buf >> (bufLen - 6)) & 0x03) != 0) {
       if (bufLen <= 12) {
 	code = buf << (12 - bufLen);
       } else {
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 42e3346..01235eb 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -1719,7 +1719,7 @@
     code = lookBits(13);
     if ((code >> 7) == 0) {
       p = &blackTab1[code];
-    } else if ((code >> 9) == 0) {
+    } else if ((code >> 9) == 0 && (code >> 7) != 0) {
       p = &blackTab2[(code >> 1) - 64];
     } else {
       p = &blackTab3[code >> 7];