You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2019/06/23 13:21:03 UTC

svn commit: r1861927 - /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java

Author: lehmi
Date: Sun Jun 23 13:21:02 2019
New Revision: 1861927

URL: http://svn.apache.org/viewvc?rev=1861927&view=rev
Log:
PDFBOX-4578: fixed/overhauled EOL detection, fixed misspelled keyword

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java?rev=1861927&r1=1861926&r2=1861927&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java Sun Jun 23 13:21:02 2019
@@ -48,6 +48,8 @@ import org.apache.pdfbox.util.Charsets;
 public class StreamValidationProcess extends AbstractProcess
 {
 
+    private static final String ENDSTREAM = "endstream";
+
     @Override
     public void validate(PreflightContext ctx) throws ValidationException
     {
@@ -220,12 +222,17 @@ public class StreamValidationProcess ext
                 if (readUntilStream(ra))
                 {
                     int c = ra.read();
-                    if (c == '\r')
+                    // "stream" has to be followed by a LF or CRLF
+                    if (c != '\r' && c != '\n')
                     {
-                        ra.read();
+                        addStreamLengthValidationError(context, cObj, length, "");
+                        return;
+                    }
+                    if (c == '\r' && ra.read() != '\n')
+                    {
+                        addStreamLengthValidationError(context, cObj, length, "");
+                        return;
                     }
-                    // else c is '\n' no more character to read
-
                     // ---- Here is the true beginning of the Stream Content.
                     // ---- Read the given length of bytes and check the 10 next bytes
                     // ---- to see if there are endstream.
@@ -255,42 +262,19 @@ public class StreamValidationProcess ext
                     }
                     while (nbBytesToRead > 0);
 
-                    int len = "endstream".length() + 2;
+                    int len = ENDSTREAM.length() + 2;
                     byte[] buffer2 = new byte[len];
-                    for (int i = 0; i < len; ++i)
-                    {
-                        buffer2[i] = (byte) ra.read();
-                    }
+                    ra.read(buffer2);
 
                     // ---- check the content of 10 last characters
+                    // there has to be an proceeding EOL (LF or CRLF)
                     String endStream = new String(buffer2, Charsets.ISO_8859_1);
-                    if (buffer2[0] == '\r' && buffer2[1] == '\n')
-                    {
-                        if (!endStream.contains("endstream"))
-                        {
-                            addStreamLengthValidationError(context, cObj, length, endStream);
-                        }
-                    }
-                    else if (buffer2[0] == '\r' && buffer2[1] == 'e')
-                    {
-                        if (!endStream.contains("endstream"))
-                        {
-                            addStreamLengthValidationError(context, cObj, length, endStream);
-                        }
-                    }
-                    else if (buffer2[0] == '\n' && buffer2[1] == 'e')
+                    if ((buffer2[0] != '\r' && buffer2[0] != '\n') //
+                            || (buffer2[0] == '\r' && buffer2[1] != '\n') //
+                            || (buffer2[0] == '\n' && buffer2[1] != 'e') //
+                            || !endStream.contains(ENDSTREAM))
                     {
-                        if (!endStream.contains("endstream"))
-                        {
-                            addStreamLengthValidationError(context, cObj, length, endStream);
-                        }
-                    }
-                    else
-                    {
-                        if (!endStream.startsWith("endStream"))
-                        {
-                             addStreamLengthValidationError(context, cObj, length, endStream);
-                        }
+                        addStreamLengthValidationError(context, cObj, length, endStream);
                     }
                 }
                 else