Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Oct 7, 2024
2 parents f1cf35c + 74fd7e5 commit 20e65ce
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions itext.tests/itext.kernel.tests/itext/kernel/utils/PdfMergerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ public virtual void MergeDocumentTest02() {
, destinationFolder, "diff_"));
}

[NUnit.Framework.Test]
public virtual void MergeDocumentWithCycleTagReferenceTest() {
String filename1 = sourceFolder + "doc1.pdf";
String filename2 = sourceFolder + "pdfWithCycleRefInParentTag.pdf";
String resultFile = destinationFolder + "pdfWithCycleRefInParentTag.pdf";
using (PdfDocument pdfDocument1 = new PdfDocument(new PdfReader(filename2))) {
using (PdfDocument pdfDocument2 = new PdfDocument(new PdfReader(filename1), CompareTool.CreateTestPdfWriter
(resultFile).SetSmartMode(true))) {
PdfMerger merger = new PdfMerger(pdfDocument2);
merger.Merge(pdfDocument1, 1, pdfDocument1.GetNumberOfPages());
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(resultFile, sourceFolder + "cmp_pdfWithCycleRefInParentTag.pdf"
, destinationFolder, "diff_"));
}

[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)]
public virtual void MergeDocumentTest03() {
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,12 @@ private static PdfDictionary GetTopmostParent(PdfMcr mcr) {
}

private static IList<PdfDictionary> RetrieveParents(PdfMcr mcr, bool all) {
IList<PdfDictionary> parents = new List<PdfDictionary>();
ICollection<PdfDictionary> parents = new LinkedHashSet<PdfDictionary>();
IStructureNode firstParent = mcr.GetParent();
PdfDictionary previous = null;
PdfDictionary current = firstParent is PdfStructElem ? ((PdfStructElem)firstParent).GetPdfObject() : null;
while (current != null && !PdfName.StructTreeRoot.Equals(current.GetAsName(PdfName.Type))) {
while (current != null && !PdfName.StructTreeRoot.Equals(current.GetAsName(PdfName.Type)) && !parents.Contains
(current)) {
if (all) {
parents.Add(current);
}
Expand All @@ -648,7 +649,7 @@ private static IList<PdfDictionary> RetrieveParents(PdfMcr mcr, bool all) {
if (!all) {
parents.Add(previous);
}
return parents;
return new List<PdfDictionary>(parents);
}

//\cond DO_NOT_DOCUMENT
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a6e77ae175f64fa2b5f619945eab96b1d23c371d
a0fc8b8fe2956f080130695f69f406bc43a9f980

0 comments on commit 20e65ce

Please sign in to comment.