diff options
author | Simon Steiner <ssteiner@apache.org> | 2018-09-21 12:24:47 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2018-09-21 12:24:47 +0000 |
commit | 8b45160da2f405fcd7d41d5be1dd362f80a0c6db (patch) | |
tree | c825dd5327afac6d6d12dd7b606395f0bc109337 /fop-core/src/main | |
parent | 51ef3fa6bd23b1231ad2f7935a4c303fd106a252 (diff) | |
download | xmlgraphics-fop-8b45160da2f405fcd7d41d5be1dd362f80a0c6db.tar.gz xmlgraphics-fop-8b45160da2f405fcd7d41d5be1dd362f80a0c6db.zip |
FOP-2811: PDF larger than 100k pages can have wrong content stream
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1841574 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src/main')
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/pdf/PDFStream.java | 17 | ||||
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java | 4 |
2 files changed, 16 insertions, 5 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFStream.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFStream.java index c5a8ad083..e8ed5fc04 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFStream.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFStream.java @@ -24,7 +24,8 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import java.util.Arrays; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; /** * Class representing a PDF stream. @@ -193,9 +194,19 @@ public class PDFStream extends AbstractPDFStream { return len; } - public int streamHashCode() throws IOException { + public String streamHashCode() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); outputRawStreamData(bos); - return Arrays.hashCode(bos.toByteArray()); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] thedigest = md.digest(bos.toByteArray()); + StringBuilder hex = new StringBuilder(); + for (byte b : thedigest) { + hex.append(String.format("%02x", b)); + } + return hex.toString(); + } catch (NoSuchAlgorithmException e) { + throw new IOException(e); + } } } diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index 34a12cb14..da69fae63 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -98,7 +98,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { = new PDFDocumentNavigationHandler(this); private Map<Integer, PDFArray> pageNumbers = new HashMap<Integer, PDFArray>(); - private Map<Integer, PDFReference> contents = new HashMap<Integer, PDFReference>(); + private Map<String, PDFReference> contents = new HashMap<String, PDFReference>(); /** * Default constructor. @@ -307,7 +307,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { private void setUpContents() throws IOException { PDFStream stream = generator.getStream(); - int hash = stream.streamHashCode(); + String hash = stream.streamHashCode(); if (!contents.containsKey(hash)) { pdfDoc.registerObject(stream); PDFReference ref = new PDFReference(stream); |