Issue 512 revisited. Use of hashset to avoid reprocessing same token in infinite loop.

This commit is contained in:
Fred Natzke
2022-12-07 17:27:34 +10:00
parent 9ef07b0176
commit f5fe39b285

View File

@@ -81,11 +81,13 @@
pageNumber.Increment();
return new PageTreeNode(nodeDictionaryInput, referenceInput, true, pageNumber.PageCount).WithChildren(EmptyArray<PageTreeNode>.Instance);
}
//If we got here, we have to iterate till we manage to exit
}
//If we got here, we have to iterate till we manage to exit
HashSet<int> visitedTokens = new HashSet<int>(); // As we visit each token add to this list (the hashcode of the indirect reference)
var toProcess =
new Queue<(PageTreeNode thisPage, IndirectReference reference, DictionaryToken nodeDictionary, IndirectReference parentReference,
@@ -103,7 +105,15 @@
do
{
var current = toProcess.Dequeue();
if (current.reference.GetHashCode() == current.parentReference.GetHashCode()) { continue; } // Issue #519
var currentReferenceHash = current.reference.GetHashCode();
if (visitedTokens.Contains(currentReferenceHash))
{
continue; // don't revisit token already processed. break infinite loop. Issue #512
}
else
{
visitedTokens.Add(currentReferenceHash);
}
if (!current.nodeDictionary.TryGet(NameToken.Kids, pdfTokenScanner, out ArrayToken kids))
{
if (!isLenientParsing)