mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-27 11:37:59 -06:00
An outline whose items name shared children (/First and /Next pointing at nodes that other items also name) was counted by following every path. With 60 levels of two items each, a walk that follows every path takes 2^60 steps. The outline count never finished, and Remove Hidden Information and Sanitize both run that count first. The count now keeps the set of items it has reached. An item reached a second time is not counted again, and the level stops there: the walk that reached the item first goes on to count the rest of that level. A total budget of 100,000 distinct items bounds the work for an outline with very many items. The per-level cap is unchanged. Ordinary outlines count as before. The existing hidden-information test (two bookmarks) passes unchanged, and a new nested outline test (five items) pins the count for nesting and siblings. Tests added in crates/redact/src/tests.rs: - an_outline_whose_items_share_children_is_counted_without_spinning - removing_bookmarks_from_an_outline_whose_items_share_children_finishes - an_outline_counts_no_more_items_than_its_total_budget - a_nested_outline_is_counted_item_by_item The first, second and third were seen to fail on the code before this change: the first two timed out after 10 seconds, and the third read 120000 where 100000 is expected. The fourth passes before and after the change and guards the ordinary count. The spin tests run the walk on a thread with a 10 second bound, so a regression fails the test instead of hanging the run. Reverting only the shared-item check, or only the budget check, fails the tests they pin. Checked with cargo fmt --all -- --check, clippy with -D warnings on pdfcraft-redact, and cargo test for pdfcraft-redact.