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:23:51 UTC
svn commit: r1861930 - in /pdfbox/branches/issue4569: ./
preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Author: lehmi
Date: Sun Jun 23 13:23:51 2019
New Revision: 1861930
URL: http://svn.apache.org/viewvc?rev=1861930&view=rev
Log:
PDFBOX-4578: fixed/overhauled EOL detection, fixed misspelled keyword
Modified:
pdfbox/branches/issue4569/ (props changed)
pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
Propchange: pdfbox/branches/issue4569/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jun 23 13:23:51 2019
@@ -1,3 +1,4 @@
/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712,1799081-1799082,1814046,1814285,1814459,1824914,1825811,1825820,1825912,1844477,1844516,1844519,1844567,1850577,1857953,1858696,1858698,1860825
/pdfbox/branches/no-awt:1618517-1621410
/pdfbox/no-awt:1618514-1618516
+/pdfbox/trunk:1861927
Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java?rev=1861930&r1=1861929&r2=1861930&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/process/StreamValidationProcess.java Sun Jun 23 13:23:51 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