pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1861928 - in /pdfbox/branches/2.0: ./ preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Date Sun, 23 Jun 2019 13:22:56 GMT
Author: lehmi
Date: Sun Jun 23 13:22:56 2019
New Revision: 1861928

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

Modified:
    pdfbox/branches/2.0/   (props changed)
    pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java

Propchange: pdfbox/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jun 23 13:22:56 2019
@@ -1,4 +1,4 @@
 /pdfbox/branches/issue4569:1861285,1861586
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516
-/pdfbox/trunk:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1743248,1745595,1745606,1745772,1745774,1745776,1745779,1746032,1746151,1749162,1749165,1749432,1766088,1766213,1767585,1768061,1770985,1770988,1772528,1778172,1782679,1786586,1786603,1787546,1789414,1790745,1794073,1794090,1794620,1794753,1794859,1794891,1800566,1812426,1814226,1826836,1857800,1857803,1857914
+/pdfbox/trunk:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1743248,1745595,1745606,1745772,1745774,1745776,1745779,1746032,1746151,1749162,1749165,1749432,1766088,1766213,1767585,1768061,1770985,1770988,1772528,1778172,1782679,1786586,1786603,1787546,1789414,1790745,1794073,1794090,1794620,1794753,1794859,1794891,1800566,1812426,1814226,1826836,1857800,1857803,1857914,1861927

Modified: pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java?rev=1861928&r1=1861927&r2=1861928&view=diff
==============================================================================
--- pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
(original)
+++ pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Sun Jun 23 13:22:56 2019
@@ -50,6 +50,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
     {
@@ -226,12 +228,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.
@@ -261,42 +268,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



Mime
View raw message