Files
pdfcraft/crates
00c357ac71 fix(xfa): remap bookmarks and named destinations to the pages a relayout writes (#9027) (#9080)
* fix(xfa): remap bookmarks and named destinations to the pages a relayout writes (#9027)

After an XFA form is laid out again, the document's pages are replaced, so
bookmarks and named destinations that named the old pages pointed at orphaned
objects. Remap them to the replacements by page position (a destination naming
a page the layout dropped goes to the last page written); destinations naming
untouched pages or non-page targets are left alone.

- xfa/pdf.rs: page_list (the pages a layout replaces, in reading order);
  write_form captures the old pages before page creation and remaps
  destinations after the new pages are written; remap_destinations handles
  /Dests, /Outlines (bookmark items, /Next chains and /Kids), and /Names
  (Dests and Pages categories); remap_dest / remap_action / remap_name_tree
  update indirect objects in place.
- xfa/fixtures.rs: dests_shell, a shell with /Dests, /Names and two /Outlines
  items (a /Dest and a GoTo action) naming the placeholder page.
- engine/tests.rs: xfa_relayout_keeps_bookmarks_and_named_destinations_on_the_pages_it_writes.

Co-authored-by: Copilot <[email protected]>

* fix(xfa): bound the destination remap's walks and remap what they omit (#9027 review)

The remap that points bookmarks and named destinations at the pages a
relayout writes could walk a malformed document forever, and silently left
a destination stale when a search hit its bound:

- xfa/pdf.rs: page_list errors on a page tree that lists a node twice,
  and on one past MAX_PAGES_SEARCHED, before any page is replaced; the
  outline walk follows each item's /First child (the spec's way) and
  errors at the bound instead of truncating; /Names categories are
  handled per category, the Pages one's values being page references
  remapped through the map directly (remap_page_ref); remap_dest,
  remap_action and remap_name_tree take a visited set, a /D chain or
  /Kids chain that repeats being an error before the recursion
  continues.
- xfa/fixtures.rs: the name-tree key is the string (end), as the spec
  requires.
- xfa/pdf.rs tests: each fix is guarded by a test that fails without it;
  automation hostile_args: the cyclic page tree, destination, and name
  tree are in the hostile-input sweep.

Co-authored-by: Copilot <[email protected]>

* fix(xfa): count pages and bookmarks at acceptance, pin the position remap (#9027 review)

- page_list: the 10,000-page bound is checked when a leaf is accepted, so a tree of
  exactly the bound followed by an empty /Pages node is still walked.
- the bookmark walk checks `seen` before the item bound, so a repeat of an item
  already counted is not a new item.
- tests for 3 old pages onto 2 and 2 onto 3, each with a bookmark, a /Dests entry and
  a /Names entry, plus one for each bound case above.
- remap_destinations' doc says what an error leaves behind: the walks after the bookmark
  walk can fail once earlier ones were written.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(xfa): a page tree the remap cannot list is a warning, not a failed layout (#9027)

Main's relayout tests (cyclic page trees, a shared-reference page subtree past the walk bound)
expect the layout to be written. The destination remap now reports what it could not do as a
warning and keeps the layout, instead of failing the whole relayout.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: FredApps <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
2026-12-04 16:12:36 +01:00
..
2026-11-26 23:00:01 +07:00