Skip to content

Commit 47cd340

Browse files
ars18wrwitext-teamcity
authored andcommitted
Check copied outline's destination on null reference. Add a test.
DEVSIX-1660 Autoported commit. Original commit hash: [f2eea8ee7]
1 parent bcf7868 commit 47cd340

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ public virtual void MergeDocumentTest01() {
9090
}
9191
}
9292

93+
/// <exception cref="System.IO.IOException"/>
94+
/// <exception cref="System.Exception"/>
95+
[NUnit.Framework.Test]
96+
[LogMessage(iText.IO.LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
97+
public virtual void MergeDocumentOutlinesWithNullDestinationTest01() {
98+
String resultFile = destinationFolder + "mergeDocumentOutlinesWithNullDestinationTest01.pdf";
99+
String filename = sourceFolder + "null_dest_outline.pdf";
100+
PdfDocument sourceDocument = new PdfDocument(new PdfReader(filename));
101+
PdfMerger resultDocument = new PdfMerger(new PdfDocument(new PdfWriter(resultFile)));
102+
resultDocument.Merge(sourceDocument, 1, 1);
103+
resultDocument.Close();
104+
sourceDocument.Close();
105+
CompareTool compareTool = new CompareTool();
106+
String errorMessage = compareTool.CompareByContent(resultFile, sourceFolder + "cmp_mergeDocumentOutlinesWithNullDestinationTest01.pdf"
107+
, destinationFolder, "diff_");
108+
if (errorMessage != null) {
109+
NUnit.Framework.Assert.Fail(errorMessage);
110+
}
111+
}
112+
93113
/// <exception cref="System.IO.IOException"/>
94114
/// <exception cref="System.Exception"/>
95115
[NUnit.Framework.Test]

itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,8 +2111,11 @@ private void CloneOutlines(ICollection<PdfOutline> outlinesToCopy, PdfOutline ne
21112111
}
21122112
foreach (PdfOutline outline in oldParent.GetAllChildren()) {
21132113
if (outlinesToCopy.Contains(outline)) {
2114-
PdfObject destObjToCopy = outline.GetDestination().GetPdfObject();
2115-
PdfDestination copiedDest = GetCatalog().CopyDestination(destObjToCopy, page2page, toDocument);
2114+
PdfDestination copiedDest = null;
2115+
if (null != outline.GetDestination()) {
2116+
PdfObject destObjToCopy = outline.GetDestination().GetPdfObject();
2117+
copiedDest = GetCatalog().CopyDestination(destObjToCopy, page2page, toDocument);
2118+
}
21162119
PdfOutline child = newParent.AddOutline(outline.GetTitle());
21172120
if (copiedDest != null) {
21182121
child.AddDestination(copiedDest);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0d625679cd2f5be0c7fc50d62a423267b7244f4f
1+
f2eea8ee75c83026cba91bb84d1833c59d08bcf0

0 commit comments

Comments
 (0)