Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E3401063F for ; Mon, 9 Sep 2013 17:15:29 +0000 (UTC) Received: (qmail 22224 invoked by uid 500); 9 Sep 2013 17:15:29 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 22193 invoked by uid 500); 9 Sep 2013 17:15:25 -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 22186 invoked by uid 99); 9 Sep 2013 17:15:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Sep 2013 17:15:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Sep 2013 17:15:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A915323889D5; Mon, 9 Sep 2013 17:14:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1521194 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Date: Mon, 09 Sep 2013 17:14:59 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130909171459.A915323889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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)