mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-01-18 19:51:24 +08:00
Issue 512 revisited. Use of hashset to avoid reprocessing same token in infinite loop.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user