Skip to content

Commit f2eea8e

Browse files
committed
Check copied outline's destination on null reference. Add a test.
DEVSIX-1660
1 parent 0d62567 commit f2eea8e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,8 +2092,11 @@ private void cloneOutlines(Set<PdfOutline> outlinesToCopy, PdfOutline newParent,
20922092
}
20932093
for (PdfOutline outline : oldParent.getAllChildren()) {
20942094
if (outlinesToCopy.contains(outline)) {
2095-
PdfObject destObjToCopy = outline.getDestination().getPdfObject();
2096-
PdfDestination copiedDest = getCatalog().copyDestination(destObjToCopy, page2page, toDocument);
2095+
PdfDestination copiedDest = null;
2096+
if (null != outline.getDestination()) {
2097+
PdfObject destObjToCopy = outline.getDestination().getPdfObject();
2098+
copiedDest = getCatalog().copyDestination(destObjToCopy, page2page, toDocument);
2099+
}
20972100
PdfOutline child = newParent.addOutline(outline.getTitle());
20982101
if (copiedDest != null) {
20992102
child.addDestination(copiedDest);

kernel/src/test/java/com/itextpdf/kernel/utils/PdfMergerTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ public void mergeDocumentTest01() throws IOException, InterruptedException {
107107
}
108108
}
109109

110+
@Test
111+
@LogMessages(messages = {
112+
@LogMessage(messageTemplate = LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)
113+
})
114+
public void mergeDocumentOutlinesWithNullDestinationTest01() throws IOException, InterruptedException {
115+
String resultFile = destinationFolder + "mergeDocumentOutlinesWithNullDestinationTest01.pdf";
116+
String filename = sourceFolder + "null_dest_outline.pdf";
117+
PdfDocument sourceDocument = new PdfDocument(new PdfReader(filename));
118+
119+
PdfMerger resultDocument = new PdfMerger(new PdfDocument(new PdfWriter(resultFile)));
120+
resultDocument.merge(sourceDocument, 1, 1);
121+
resultDocument.close();
122+
sourceDocument.close();
123+
124+
CompareTool compareTool = new CompareTool();
125+
String errorMessage = compareTool.compareByContent(resultFile, sourceFolder + "cmp_mergeDocumentOutlinesWithNullDestinationTest01.pdf", destinationFolder, "diff_");
126+
if (errorMessage != null) {
127+
Assert.fail(errorMessage);
128+
}
129+
}
130+
110131
@Test
111132
public void mergeDocumentTest02() throws IOException, InterruptedException {
112133
String filename = sourceFolder + "doc1.pdf";

0 commit comments

Comments
 (0)