Skip to content

Commit

Permalink
close #163: Infinite loop parsing PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
ediweissmann committed Sep 25, 2023
1 parent 92ad538 commit 2af172b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/sejda/sambox/input/XrefParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void onEntryFound(XrefEntry entry)
}
};
}

private HashSet<Long> catalogSeenOffsets = new HashSet<>();

/**
* parse the xref using the given parser.
Expand Down Expand Up @@ -139,9 +141,14 @@ else if (line.contains(COSName.CATALOG.getName()))
long position = parser.position();
try
{
// we do our best to make sure we have a catalog even in corrupted docs
LOG.debug("Parsing potential Catalog at {}", lastObjectOffset);
onPotentialCatalog();
if(catalogSeenOffsets.contains(lastObjectOffset)){
LOG.debug("Already parsed potential Catalog at {}, skipping", lastObjectOffset);
} else {
catalogSeenOffsets.add(lastObjectOffset);
// we do our best to make sure we have a catalog even in corrupted docs
LOG.debug("Parsing potential Catalog at {}", lastObjectOffset);
onPotentialCatalog();
}
}
catch (IOException e)
{
Expand Down Expand Up @@ -200,6 +207,9 @@ private void onPotentialCatalog() throws IOException
}
trailer.setFallbackScanStatus(xrefScanStatus.name());
}

// cleanup
catalogSeenOffsets.clear();
}

/**
Expand Down

0 comments on commit 2af172b

Please sign in to comment.