Main (#5569) decodes every image through cos's ImageBudget, which counts the
JBIG2 decoder's own work and the globals it reads, through main's own
restore_shared_jbig2 and image::without_globals for the images that share a
redacted image's /JBIG2Globals too. This branch replaces both with
globals::unshare, so the merge keeps unshare and drops them.
without_dictionary now decodes through ImageBudget::decode instead of
Document::decoded_image_within, which main made private. That closes the gap
the PR noted: the decoder's own work (up to hayro-jbig2's 2^30 steps an image)
was charged one unit of the run budget. apply passes its run's allowance, what
clearing left of it, as main's restore did. Past it apply is refused with
ImagesPastAllowance, as main's restore was. remove_hidden gives unshare an
allowance of its own (sanitize::unshare_unmarked), and past it is refused with
SharedJbig2Budget: "redact fewer pages at a time" means nothing there, and
Optimize's discard runs it too. SharedJbig2Budget's text now says finding and
storing again.
Tests: main's allowance test runs on unshare, with ImageBudget::with_work(0)
refused as ImagesPastAllowance, through unshare_unmarked as SharedJbig2Budget,
and u64::MAX storing one image. Test helpers decode through ImageBudget, since
Document::decoded_image is no longer public.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
The centred 4 pt strip still covered the right 3 pt of the page's
scrollbar beside a right-docked pane. Register the host's resize edge
again from the border rightwards, on the host's own layer, and leave an
inert edge inert. The test now hovers and drags both scrollbars beside a
right-docked Tools pane (CodeRabbit) and checks the width is unchanged.
`form_fill` with each option `form_fields` reports ticks the kid of that on state, also where
the other kid's `/Opt` export is that on state (ISO 32000-2 §12.7.5.2.3, Table 230).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
A review of ecf028965 measured that decoding an image undoes the filters
of each dictionary it names again when cos doesn't hold their bytes (20
images naming a 32 MiB dictionary: 1.2 s at 2 units each). content()
now remembers what each dictionary decoded to, or its limit when it
couldn't, and an image is charged that before it is decoded.
Names gathered from many entries are held as a set as they are read, so
a million entries naming one chain hold it once. The claim that each
object is fetched once a run for each way it is read says its exception:
a /JBIG2Globals chain named part way is followed again from there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
Conflicts:
- crates/redact/src/lib.rs: main added the run's ImageBudget to Applying
and Scope::new; kept both sides (the removed-text fields and the image
budget), with main's refused-images check before the destructuring.
- crates/redact/src/tests.rs (auto-merged): this PR's two tests that build
a Scope or an Applying now pass main's ImageBudget.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
The run and byte limits were per page, and a glyph's /ToUnicode text can
be 256 UTF-16 units, so a short content stream could keep gigabytes of
removed text across pages. The document now keeps at most 16 MiB; past
that the rest is not kept and the metadata check fails closed, as for any
other text it couldn't keep (CodeRabbit's retained concern on #2539).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Main's knockout-group patch now uses (67) in vendor/hayro-interpret, so
this branch's patch takes the next number free on main and in the open
reply-appearance patch (75): (76) in vendor/README.md's two columns and in
every `PdfCraft patch` comment of the View auto state (interpret/mod.rs,
ocg.rs, render's inspect/resources.rs). No code change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/render/src/raster.rs (RenderConfig): main added `jbig2_work`
next to this branch's `for_print`; both fields are kept.
- vendor/README.md (hayro-interpret row): kept main's row (patches up to
(74), including its new (73)) and put this branch's (67) entries back
in their place in both columns. Main's code now uses (67) for its
knockout-group patch, so the next commit renumbers this branch's patch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
A review of fee25bfe4 found three costs the budget didn't count:
- A /JBIG2Globals reference in parameters given directly was fetched
again for every entry of every stream (2,000 entries, 53 KB: 40 s, two
thousand units of four million). What a reference leads to is now
remembered for the run under it, and a chain met part way takes what
is known from there.
- A /Filter name was kept whatever it was, so a 32 MiB name referred to
nine times was held nine times and copied for each image (725 MiB from
2.8 KB). Only a name a decoder knows is kept; any other is no filter,
and a name longer than any decoder's isn't looked at.
- A decode that failed spent nothing, so a dictionary one byte past its
limit escaped the budget. A failure now costs as much as it was allowed
to decode: a dictionary MAX_JBIG2_GLOBALS, an image its allowance.
The README says what the budget counts, and that past it the redaction
is refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
Conflicts:
- crates/xfa/src/parse.rs: main added quarter_turns before parse_common
(and rotate in its body); this branch gave parse_common a warnings
parameter for the property trees. Kept quarter_turns and the branch's
signature; the body holds both props and rotate.
- crates/xfa/src/tests.rs: both sides added tests at the end of the file
(this branch's packet-size test; main's rotated-draw tests). Kept both.
- parity/acrobat-features.toml (form.xfa-dynamic): main put the
rotated-draw test at the front of the evidence and a sentence at the
front of the notes; kept this branch's lines with main's additions
prepended.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- parity/acrobat-features.toml (form.xfa-dynamic): main added the
rotated-draw test to the front of the evidence and a sentence to the
front of the notes; this branch appended the prototype tests to the
evidence and put "prototypes first: ..." into the layout sentence of
the notes. Kept both on main's lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/layout/measure.rs (positioned width and height): this
branch measures each child under its own SOM index (size_at with
sibs.at(i)); main reads the extent through standing_box so a turned
draw counts as the box it stands in. Kept both: size_at for the size,
standing_box(w, h).right() / .bottom() for the extent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/tests.rs: both sides appended tests at the end of the
file; kept this branch's subformSet tests and main's draw/anchor
tests, closing the branch's last test before main's block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/engine/src/tests.rs: both sides appended tests at the end of
the file; kept this branch's page-master tests and main's page and
image edit tests, closing the branch's last test before main's block.
- crates/xfa/src/tests.rs: the same, with main's draw/anchor tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/tests.rs: both sides added tests at the end of the file
(this branch's XFAImages name-tree tests; main's rotated-draw tests).
Kept both, closing the branch's last test before main's helpers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/tests.rs: both sides appended tests at the end of the
file; kept this branch's unique-name tests and main's draw/anchor
tests, closing the branch's last test before main's block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- vendor/README.md (hayro-interpret row): kept main's row, including its
new (73) and the extended (11)/(31) notes, and re-inserted this PR's (53)
entries (unused on main) in numeric position in both columns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/tests.rs: both sides appended tests at the end of the
file; kept this branch's row minH test and main's draw/anchor tests,
closing the branch's test before main's block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
- crates/ui-egui/src/canvas.rs (apply_frame_requests): main passes the leftmost page edge to quick_bar; this branch hides the quick bar when the document hides its toolbars. Kept both: the branch's HideToolbar condition with main's page_left call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Conflicts:
- crates/xfa/src/tests.rs: both sides added tests at the end of the file
(this branch's flowed table-cell and content-height tests; main's
rotated-draw tests). Kept both, closing the branch's last test before
main's helpers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyG234xeYkJfr41E6iP
Reviews kept finding ways a small file could make this run long or large:
readable() fetched the same objects again for each image that names a
dictionary (~3.9 s each when two large objects push each other out of
cos's caches), and the memo of names grew with distinct arrays times
their entries (~3.7 GB from 2 MiB). Nothing bounded the run as a whole.
Everything unshare reads now goes through one Run: what a reference
leads to is fetched at most once a run for each way it is read (a size, a
filter, parameters, an entry, a flag, /F, a colour space, an ICC
profile), looked up before it is fetched and kept only as what is read
of it. Objects fetched, names remembered, and what is decoded (a unit for
each 4 KiB) count against RUN_BUDGET (2^22), and past it the run is
refused with SharedJbig2Budget. A scan reads a few objects a page, so a
book of thousands of pages sharing one dictionary stays well within it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
Conflicts:
- vendor/README.md (hayro-interpret row): kept main's row; main does not
use patch number (67), so this PR's (67) entries go in numeric position
(before (71)) in both the Patches and Test columns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
Conflicts:
- vendor/README.md (hayro-interpret row): kept main's row; main does not
use patch number (53), so this PR's (53) entries go in numeric position
(before (55)) in both the Patches and Test columns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
Conflicts:
- crates/ui-egui/src/workflows/js_ui.rs: main moved the Preferences dialog to
crates/ui-egui/src/dialogs/preferences.rs (cards with search). Took main's re-export and
carried this branch's "Otherwise, ask on the first save after a signature is placed"
checkbox into card_fill_and_sign, disabled while flattening is on as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyCfwzyRXj4VfQAVVdv
f5aa20f7a keyed what Names remembers by the object references end at,
but followed them all before looking: every hit fetched the object
again. With two large objects that push each other out of cos's caches,
each fetch decoded 17 MiB, and a 66 KiB file took 26 s where it took
0.6 s. Each reference is now looked up before it is fetched, and what
it leads to is remembered under every reference on the way, with the
key of the last: a hit fetches nothing, an alias or a chain only the
references before what is remembered. The test counts fetches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
`ImageBudget::decode` is now the one public way to decode an image's
CCITT fax or JBIG2 data: `Document::decoded_image` and
`decoded_image_within`, which decoded with no limit on the work, are
test-only in pdfcraft-cos, and pdfcraft-filters exports only
`decode_ccitt_within` and `decode_jbig2_within`, which spend from a
caller's allowance (`decode_jbig2` is gone, `decode_ccitt` private).
So an operation over many images can't decode them without sharing an
allowance; the compiler holds new callers to it. Doctests that must not
compile check both crates; with the old entry points public they fail.
Tests outside the crates decode through an unlimited ImageBudget.
Streams in general (`Stream::decoded`) are left for a follow-up.
Names kept what a value names by its first reference, so streams naming
one array each through an object of their own that refers to it missed
the memo every time: quadratic time, and now memory too (8000 such
streams with 8000 entries, 1.4 MB: 30 s, 504 MiB). It is keyed by the
object the references end at, so another reference, or a chain, finds it
(the same file: 0.29 s, 7 MiB, measured by the review). matches and
added use the same key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
A wheel notch sets `turned`, and only a trackpad touch or a smooth burst
cleared it. With a wheel that macOS reports in points, a notch that
turned the page left `gesture_turned` set, so read_wheel swallowed every
later notch on that page. The same happened at the last page's bottom
edge.
A notch that cannot turn now clears `turned`. The new tests use Point
notches. The Line-unit test in b31b4035 passes without either fix,
because egui's own ScrollArea still applies line scrolling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three ways a small file could still make a redaction run long or large:
- direct_parms kept /JBIG2Globals as given, so a direct array there was
copied for each entry (427 MiB from 32 KB). It is kept only when it is a
reference, as Document::with_direct_parms keeps it; a direct value is
no stream, so no decoder reads it.
- The entries copied were bounded only by /Filter's length, and the work
repeated for every stream that uses a dictionary: time grew with the
square of the file (117 s from 249 KB). A /Filter longer than any
decoder takes (MAX_CHAIN, and a /Crypt) is read as no filter, so its
parameters aren't read either; no decoder reads such a stream anyway.
- named() read every entry of every stream's parameters, through up to
33 references each, with nothing shared between streams. Names keeps
what each value the file refers to names, for the whole run, so streams
sharing an array or an entry cost it once; unshare adds a shared list,
and finds what it matches, once too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmsdeUCdTaD72jkDw2pJKY
It reserves room for a translated "Mixed", and in Czech or French that pushed the alignment
button up to 54 pt past the Tools pane. The field is now no wider than SIZE_FIELD, and a longer
translation scrolls in it. The language test checks the size row too.