Skip to content

Commit

Permalink
optimize: add a recursion guard to avoid chasing cyclic form xobjects
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed Jun 1, 2024
1 parent 2b0c6cf commit 981bbf1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ocrmypdf/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def _find_image_xrefs_container(
for _imname, image in dict(xobjs).items():
if image.objgen[1] != 0:
continue # Ignore images in an incremental PDF
xref = Xref(image.objgen[0])
if xref in include_xrefs or xref in exclude_xrefs:
continue # Already processed
if Name.Subtype in image and image.Subtype == Name.Form:
# Recurse into Form XObjects
log.debug(f"Recursing into Form XObject {_imname} in page {pageno}")
Expand All @@ -269,7 +272,6 @@ def _find_image_xrefs_container(
depth + 1,
)
continue
xref = Xref(image.objgen[0])
if Name.SMask in image:
# Ignore soft masks
smask_xref = Xref(image.SMask.objgen[0])
Expand Down

0 comments on commit 981bbf1

Please sign in to comment.