Repository navigation
feat!: share ReaderRequirements (rreq) through Payload and MetadataList, read once - #784
Open
D0ubleD0uble wants to merge 4 commits into
Open
D0ubleD0uble wants to merge 4 commits into
D0ubleD0uble wants to merge 4 commits into
Conversation
…st, read once The rreq masks become Payload and its feature lists MetadataList. The box is read once, in the pass that keeps what it builds; the measure pass only checks it, and walks it again only for masks long enough to share a chunk. The header shares the kept copy instead of a second one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
…re a chunk Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
The rreq entries are 32 and 40 bytes for features of 2 and 16 bytes, so the box can hold more than 3.2 bytes for each byte of it. Only the first is read and it has at most 65535 features of each kind, so the bounds now add about 4.6 MiB for it wherever the 3.2 figure is cited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #783
What changes
ReaderRequirements::fully_understand,decode_completely,StandardFeature::maskandVendorFeature::maskare aPayload.standard_featuresandvendor_featuresare aMetadataList. This is the design feat!: share reported box payloads through an opaque Payload type, copied once #769 and feat!: make Jp2Metadata.color_specifications a MetadataList #780 used for the other boxes.rreq::read(it replacesrreq::parse) first checks the box without allocating. In the measure pass ofCopier::twiceit builds nothing. It walks the box again only whenML≥ 16, so the masks that go in a shared chunk get measured. In the emit pass it builds the box once, throughCopierandlist::Extender.Passthroughcarries arreq_seenflag instead of a clone of the keptrreq.open_boxestakes the flag, not a second copy. The header getskept.rreq.clone(), which shares the masks and the lists.rreq". See the note on the bound below. The places are SECURITY.md (the three bound sentences, the incremental list and step 1), README.md, docs/resource-bounds.md (three citations, the JP2 box records section and a new measurement table), docs/incremental-decoding.md, theIncrementalDecoder::headerrustdoc, and thedecode/DecodeOptions::sample_limitrustdoc insrc/lib.rs. The CHANGELOG "Migrating from 0.5" covers therreqfields, and a Changed entry gives the numbers.Acceptance
header()shares therreq(pointer test that fails on main)tests/incremental_header_payloads.rs::header_shares_the_rreq_across_calls. It coversML1 and 16, before and after the codestream, and 70 features (past a block). Entry pointers, and forML16 the mask pointers, are equal across a repeat call and a call on more bytes, and the FUAM/DCM masks are adjacent in one chunk. Fails on main (line 438, the entry pointers differ).tests/rreq_alloc.rs(counting allocator), onML0, NSF = NVF = 65535. One-shot: heap held < 4.2, peak < 4.4, allocated in all < 8.6 bytes a byte. Incremental: a secondheader()allocates < 4 KiB and shares the entries. Fails on main (peak 8.00, allocated 24.0).rreq_allocfails (allocated). M2: the header deep-copies the lists →header_shares_the_rreq_across_callsfails. M3: the measure pass skips the shared masks → the same test fails (payloads.rs"a payload not measured"). M4: the open last box reads a secondrreq→a_last_rreq_of_length_0_counts_only_as_the_firstfails. M5: masks copied withcopy_of, not into the chunk → the adjacency check fails.Debugand oracle snapshots unchanged.jp2/.jphfixtures undertests/fixtures, in default,ColorOutput::Srgbandstrict(false):format!("{:?}")ofdecode_with(samples included) and ofread_header_with, from a release build on main 2b85059 and on this branch. 267 files,cmp: 0 differ. 6 of the outputs carry anrreq. The oracle snapshot tests pass.auto_traits, rustdoc, docstests/auto_traits.rschecksMetadataList<StandardFeature>andMetadataList<VendorFeature>. Newa_feature_entry_is_the_size_the_docs_givechecks the 32/40-byte entries (24/36 on 32-bit). It also runs in the wasm32 lib tests.Measurements
One
rreqbefore thejp2coftests/fixtures/jp2_sycc_422_even.jp2, by the method in docs/resource-bounds.md: a release program that reads the file and then callsdecode, or feeds it all and callsheaderonce and then 10 more times. Heap is from a counting allocator, in bytes for each byte of the box. Resident peak is/usr/bin/time -vover a no-featurerreqbaseline, input included, in MiB. Load was 3 to 4.rreq(box)header()call before → afterThe incremental first call matches the one-shot figures. Resident held after
decode, over the baseline, was 11 to 16 MiB before and is 2.7 to 3.7 MiB now.The bound: please judge
The heap held at
ML0 is still about 4.07 bytes for each byte of the box, not 3.2. The entries themselves set that: aStandardFeatureis 32 bytes for 2 bytes of box, and aVendorFeatureis 40 for 16. A box of standard features alone holds about 16 bytes for each byte of it. Only the firstrreqis read, though, and it has at most 65535 features of each kind. So its entries are capped at about 4.6 MiB whatever its size, and any mask over 15 bytes counts as payload bytes under 3.2. The docs now say "up to about 3.2 bytes for each byte of JP2 metadata boxes and about 4.6 MiB more for the firstrreq" wherever the 3.2 figure is cited. That is the issue's "narrower honest bound" option. Shrinking the entries below 32/40 bytes would need a differentPayloador a different public shape, which is outside this issue.Gate (after
rustup update stable, rustc 1.100.1)Run on ed16d50. The commit after it changes only a SECURITY.md wording.
cargo fmt --all -- --check: okcargo clippy --all-targets -- -D warnings: okcargo clippy --lib -- -D warnings: okcargo test: 2086 passed, 0 failed, 20 ignoredcargo deny check: advisories, bans, licenses, sources okRUSTDOCFLAGS=-D warnings cargo doc --no-deps: okcargo test --target wasm32-wasip1 --lib(wasmtime runner as in CI): 854 passed, 6 ignorednice, one at a time:jp2_boxes821,384 runs,header_split116,532 runs, no crashWhat to look at hardest
src/jp2/rreq.rs: the measure and emit passes must callcopier.copyin the same order for the same boxes.fieldschecks the box before either pass copies anything, so a malformed box copies nothing in both.metadata()insrc/jp2/mod.rs:kept.rreqis set only on the first call that meets the box, and the header takeskept.rreq.clone().flatten().or(open.rreq). A malformed firstrreq(Some(None)) still hides a later open one.🤖 Generated with Claude Code
https://claude.ai/code/session_01EhjiZ6QTR3gTC3QaD9m2QV