You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/01/11 17:47:05 UTC

svn commit: r1896921 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java

Author: tilman
Date: Tue Jan 11 17:47:05 2022
New Revision: 1896921

URL: http://svn.apache.org/viewvc?rev=1896921&view=rev
Log:
PDFBOX-5360: allow streams smaller than 20 bytes

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java?rev=1896921&r1=1896920&r2=1896921&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java Tue Jan 11 17:47:05 2022
@@ -16,7 +16,6 @@
  */
 package org.apache.pdfbox.filter;
 
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -72,12 +71,8 @@ final class CCITTFaxFilter extends Filte
             type = TIFFExtension.COMPRESSION_CCITT_T4; // Group 3 1D
             byte[] streamData = new byte[20];
             int bytesRead = encoded.read(streamData);
-            if (bytesRead != streamData.length)
-            {
-                throw new EOFException("Can't read " + streamData.length + " bytes");
-            }
             PushbackInputStream pushbackInputStream = new PushbackInputStream(encoded, streamData.length);
-            pushbackInputStream.unread(streamData);
+            pushbackInputStream.unread(streamData, 0, bytesRead);
             encoded = pushbackInputStream;
             if (streamData[0] != 0 || (streamData[1] >> 4 != 1 && streamData[1] != 1))
             {
@@ -85,7 +80,7 @@ final class CCITTFaxFilter extends Filte
                 // found
                 type = TIFFExtension.COMPRESSION_CCITT_MODIFIED_HUFFMAN_RLE;
                 short b = (short) (((streamData[0] << 8) + (streamData[1] & 0xff)) >> 4);
-                for (int i = 12; i < 160; i++)
+                for (int i = 12; i < bytesRead * 8; i++)
                 {
                     b = (short) ((b << 1) + ((streamData[(i / 8)] >> (7 - (i % 8))) & 0x01));
                     if ((b & 0xFFF) == 1)