pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1603567 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: pdfwriter/COSWriter.java pdmodel/PDDocument.java
Date Wed, 18 Jun 2014 18:35:36 GMT
Author: lehmi
Date: Wed Jun 18 18:35:36 2014
New Revision: 1603567

URL: http://svn.apache.org/r1603567
Log:
PDFBOX-2082: avoid corruption when writing the signature as proposed by Štěpán Schejbal

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1603567&r1=1603566&r2=1603567&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Wed
Jun 18 18:35:36 2014
@@ -783,12 +783,13 @@ public class COSWriter implements ICOSVi
             SignatureInterface signatureInterface = doc.getSignatureInterface();
             byte[] sign = signatureInterface.sign(new ByteArrayInputStream(pdfContent));
             String signature = new COSString(sign).getHexString();
-            int leftSignaturerange = signaturePosition[1]-signaturePosition[0]-signature.length();
-            if(leftSignaturerange<0)
+            int startPos = signaturePosition[0] + 1; // move past "<"
+            int endPos = signaturePosition[1] - 1; // move in front of ">"
+            if (startPos + signature.length() > endPos)            
             {
                 throw new IOException("Can't write signature, not enough space");
             }
-            getStandardOutput().setPos(signaturePosition[0]+1);
+            getStandardOutput().setPos(startPos);
             getStandardOutput().write(signature.getBytes());
         }
     }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1603567&r1=1603566&r2=1603567&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Wed
Jun 18 18:35:36 2014
@@ -306,11 +306,11 @@ public class PDDocument implements Pagea
         int preferedSignatureSize = options.getPreferedSignatureSize();
         if (preferedSignatureSize > 0)
         {
-            sigObject.setContents(new byte[preferedSignatureSize * 2 + 2]);
+            sigObject.setContents(new byte[preferedSignatureSize]);
         }
         else
         {
-            sigObject.setContents(new byte[0x2500 * 2 + 2]);
+            sigObject.setContents(new byte[0x2500]);
         }
         
         // Reserve ByteRange



Mime
View raw message