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 2013/09/09 19:14:59 UTC
svn commit: r1521194 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Author: lehmi
Date: Mon Sep 9 17:14:59 2013
New Revision: 1521194
URL: http://svn.apache.org/r1521194
Log:
PDFBOX-1606: decrypt pdf before accessing trailer objects if necessary
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1521194&r1=1521193&r2=1521194&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Mon Sep 9 17:14:59 2013
@@ -94,18 +94,15 @@ public class NonSequentialPDFParser exte
/**
* EOF-marker.
*/
- protected static final char[] EOF_MARKER = new char[]
- { '%', '%', 'E', 'O', 'F' };
+ protected static final char[] EOF_MARKER = new char[] { '%', '%', 'E', 'O', 'F' };
/**
* StartXRef-marker.
*/
- protected static final char[] STARTXREF_MARKER = new char[]
- { 's', 't', 'a', 'r', 't', 'x', 'r', 'e', 'f' };
+ protected static final char[] STARTXREF_MARKER = new char[] { 's', 't', 'a', 'r', 't', 'x', 'r', 'e', 'f' };
/**
* obj-marker.
*/
- protected static final char[] OBJ_MARKER = new char[]
- { 'o', 'b', 'j' };
+ protected static final char[] OBJ_MARKER = new char[] { 'o', 'b', 'j' };
private final File pdfFile;
private final RandomAccessBufferedFileInputStream raStream;
@@ -365,15 +362,6 @@ public class NonSequentialPDFParser exte
COSDictionary trailer = xrefTrailerResolver.getTrailer();
document.setTrailer(trailer);
- // JIRA-1557 - ensure that all COSObject are loaded in the trailer
- for (COSBase trailerEntry : trailer.getValues())
- {
- if (trailerEntry instanceof COSObject)
- {
- COSObject tmpObj = (COSObject) trailerEntry;
- parseObjectDynamically(tmpObj, false);
- }
- }
// ---- prepare encryption if necessary
COSBase trailerEncryptItem = document.getTrailer().getItem(COSName.ENCRYPT);
if (trailerEncryptItem != null)
@@ -413,11 +401,23 @@ public class NonSequentialPDFParser exte
catch (Exception e)
{
throw new IOException("Error (" + e.getClass().getSimpleName()
- + ") while creating security handler for decryption: "
- + e.getMessage() /*, e TODO: remove remark with Java 1.6 */);
+ + ") while creating security handler for decryption: " + e.getMessage() /*
+ * , e TODO: remove
+ * remark with Java 1.6
+ */);
}
}
+ // PDFBOX-1557 - ensure that all COSObject are loaded in the trailer
+ // PDFBOX-1606 - after securityHandler has been instantiated
+ for (COSBase trailerEntry : trailer.getValues())
+ {
+ if (trailerEntry instanceof COSObject)
+ {
+ COSObject tmpObj = (COSObject) trailerEntry;
+ parseObjectDynamically(tmpObj, false);
+ }
+ }
// ---- parse catalog or root object
COSObject root = (COSObject) xrefTrailerResolver.getTrailer().getItem(COSName.ROOT);
@@ -1049,9 +1049,7 @@ public class NonSequentialPDFParser exte
.intValue());
if (!(parsedObjects.contains(objId) /*
- * ||
- * document.hasObjectInPool
- * ( objKey )
+ * || document.hasObjectInPool ( objKey )
*/))
{
Long fileOffset = xrefTrailerResolver.getXrefTable().get(objKey);
@@ -1223,8 +1221,7 @@ public class NonSequentialPDFParser exte
// this is not legal
// the combination of a dict and the stream/endstream
// forms a complete stream object
- throw new IOException("Stream not preceded by dictionary (offset: "
- + offsetOrObjstmObNr + ").");
+ throw new IOException("Stream not preceded by dictionary (offset: " + offsetOrObjstmObNr + ").");
}
skipSpaces();
endObjectKey = readLine();
@@ -1483,8 +1480,7 @@ public class NonSequentialPDFParser exte
}
/*
- * This needs to be dic.getItem because when we are parsing, the
- * underlying object might still be null.
+ * This needs to be dic.getItem because when we are parsing, the underlying object might still be null.
*/
COSNumber streamLengthObj = getLength(dic.getItem(COSName.LENGTH));
if (streamLengthObj == null)