From commits-return-14922-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Sun Jun 23 13:23:04 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0493C180679 for ; Sun, 23 Jun 2019 15:23:03 +0200 (CEST) Received: (qmail 3183 invoked by uid 500); 23 Jun 2019 13:23:03 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 3174 invoked by uid 99); 23 Jun 2019 13:23:03 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Jun 2019 13:23:03 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id ACB4F3A0102 for ; Sun, 23 Jun 2019 13:22:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190623132257.ACB4F3A0102@svn01-us-west.apache.org> 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