Skip to content

Cyclic Widget /Parent makes page operations fail with FzErrorFormat: code=7: cycle in resources #5101

Description

@GustavoZiel

Description of the bug

PyMuPDF raises pymupdf.mupdf.FzErrorFormat: code=7: cycle in resources when it loads or processes a page containing a Widget annotation whose /Parent entry points to itself. The malformed form-field relationship makes the complete page unusable, including operations unrelated to forms.

This seems to be distinct from #4986: the page tree is valid here. The cycle is contained in the annotation/form field graph.

Concretely, for the attached reproducer:

  • Page 0 lives at xref 4 and correctly declares /Parent 2 0 R, a /Pages node.
  • Page 0 declares /Annots [7 0 R 8 0 R].
  • Widget 7 declares /Parent 7 0 R, i.e. itself.
7 0 obj
<<
  /Type /Annot
  /Subtype /Widget
  /P 4 0 R
  /Parent 7 0 R
  ...
>>
endobj

The error fires immediately when the page is loaded.

Besides, it also occurs through Document._do_links(): insert_pdf(..., annots=False, widgets=False, links=False) can rebuild the page, but links=True fails even with annots=False and widgets=False.

The source has no actual links. The link-copy pass still loads every source page to ask for its links, which triggers the cyclic Widget-parent traversal.

How to reproduce the bug

import pymupdf

source = pymupdf.open("repro_widget_parent_cycle.pdf")

print(f"Pages: {source.page_count}")
source.load_page(0)  # raises FzErrorFormat: code=7: cycle in resources

The same failure occurs during link copying:

destination = pymupdf.open()
destination.insert_pdf(
    source,
    annots=False,
    widgets=False,
    links=True,
)
# raises FzErrorFormat: code=7: cycle in resources

repro_widget_parent_cycle.pdf is a synthetic, one-page reproducer derived from the original PDF.

PyMuPDF version

1.28.2

Operating system

Linux

Python version

3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstream bugbug outside this package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions