Skip to content

Cross-reference row cells are never parsed: parse_object receives the Submatch, not the cell #3542

Closed

Description

@ESultanik

Problem

parse_xref_row in polyfile/pdf.py recurses into the Position and Generation cells of a
cross-reference row by passing the Submatch it just created instead of the cell itself:

ret = Submatch("Position", b"", relative_offset=pos.pdf_offset - row_start, length=pos.pdf_bytes,
               parent=parent)
yield ret
yield from parse_object(ret, matcher=matcher, parent=ret, pdf_header_offset=pdf_header_offset)

The ObjectID cell two lines above passes obj_id, which is what the other three call sites of
parse_object do as well. A Submatch carries no pdf_offset, so parse_object falls through
every branch and yields nothing: the two calls are no-ops.

This predates #3464. PR #3545 moved the code into parse_xref_row verbatim rather than
changing it, because fixing it adds a PSInt submatch under every Position and Generation and
that is a change to PolyFile's output, not a guard.

Reproducer

Any PDF with a classic cross-reference table. For the two-object PDF in
tests/test_pdf.py:WELL_FORMED_PDF, the tree holds two Position and two Generation
submatches, and no PSInt beneath any of them.

Fix

Pass pos and gen_no. Confirm the four extra PSInt submatches per two-row table are wanted
before doing it — polyfile/templates/ renders the tree, and the JSON output format in
docs/json_format.md describes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions