Skip to content

LRC-LIB-CATALOG-IMPORT: the ARW6 plan keeps the probe's scattered strip reads - #1223

Closed
mdlmarkham wants to merge 4 commits into
storytold:mainfrom
mdlmarkham:glm/arw6-sparse-plan
Closed

mdlmarkham wants to merge 4 commits into
storytold:mainfrom
mdlmarkham:glm/arw6-sparse-plan

Conversation

@mdlmarkham

@mdlmarkham mdlmarkham commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Fixes the sparse-equivalence break PR #1020 reported (no issue exists for it): header_plan / preview_plan
described a Compression-32766 (ARW6) strip from part of it while the header probe validates bytes scattered
through a 30-63 MB strip. The corpus's ARW6 pair was described from zeros (and again 0xFF) and the probe failed
where the whole file decodes:

crates/raw/tests/sparse_corpus.rs: arw6-sony-ilce7rm6-apsc-land-hq.arw: differs from the whole file
  left:  Err(Unsupported("ARW6 first-half row count outside 2..=7"))
  right: Ok(RawInfo { format: Arw, width: 6592, ... })

The probe's reads on an ARW6 strip are not a prefix (docs/arw6-compression.md): per tile, parse_tile_header
walks the 13 stream header words, stream_halves reads each stream's index table, and first_half_shift decodes
the residual stream's first half — which sits behind the earlier streams' data (megabytes in). The 64 KiB
prefix the plan kept does not reach any of that.

How

  • crates/raw/src/sparse.rs:
    when an IFD's image says Compression 32766 and has one strip, tiff_plan asks arw6_keep for the strip's
    scattered reads and holes only the rest. The walk runs in stages — each one answers with a single Need:
    1. the tile table (u32 count + up to 16 24-byte entries),
    2. each tile's picture header and group tables (words 0..8),
    3. the 13 stream header words, at positions the group tables alone imply (new arw6::stream_header_positions,
      mirroring parse_tile_header's group-table walk — the two walks must agree),
    4. with the header words loaded, the probe's own parse_tile_header places each stream's index table,
    5. finally each residual first half: its byte length A is its index's first entry, and first_half_shift
      decodes those lines for the anchor offset.
  • A layout the walk cannot produce (a corrupt tile table / tile header) falls to Whole: arw6::decode stops at
    the same validation of loaded bytes, so the probe is still identical (it reads whole and the equivalence holds
    trivially). This never guesses: the keeps are exactly the bytes arw6::decode reads in header mode.
  • Want::into_plan becomes pending_plan(&mut self) (std::mem::take of the asks), so the ARW6 walk can keep
    asking after the IFD walk already returned.
  • A second finding, then holed too: these files carry their full-size JPEG as a JPEGInterchangeFormat image
    (compression 6/7, where 0x0201/0x0202 are the interchange tag and its length and image() therefore declines).
    Neither hole arm reached that IFD, so the header plan read the whole 7.4 / 16.7 MB JPEG. Nothing reads it in
    header mode, so header_plan holes its bulk (>= BULK, keeping the first 64 KiB like any image); under
    preview_plan embedded_preview wants it, so the hole is header-mode only. embedded_preview itself is
    unchanged and its output identical.

Measured

Over the full CC0 corpus (cargo xtask corpus --download, 111 raws), through the same runs the corpus test makes:

format before after
ARW (27 files, incl. the two ARW6) 10.0 % 1.7 %
the two ARW6 files alone 26 % / 28 % (printed as >25 %) ~2 % / ~1 %
CR2, CR3, DNG, RAF, RW2 3.0 / 2.6 / 3.2 / 6.4 / 7.0 % unchanged

Tests

  • crates/raw/tests/sparse_corpus.rs
    (with the corpus): both pinned ARW6 files — APS-C HQ, one tile; full-frame Compressed, four tiles — pass the
    describe-equality with skipped bytes 0 and again 0xFF, under both header_plan and preview_plan; the ARW6
    decode-sum corpus tests are unchanged.
  • Without the corpus, crates/raw/src/sparse.rs
    gains arw6_plan_keeps_the_scattered_probe_reads: synthetic arw6_testenc files (single tile with s = 3, and
    a two-tile full-frame layout) whose residual stream starts past the 512 KiB prefix, asserting (a) the plan asks
    for bytes past the prefix and (b) the buffer probes as the whole file does, for both fills. This failed pre-fix
    with the "first-half row count" error and is what keeps the walk honest when the corpus is absent (which is why
    CI never saw this).

Verification

fmt, clippy -D warnings, heif, parity (+ summary refreshed), layers, assets and wasm all pass individually
(cargo xtask ci stops at the test step on this Windows machine). cargo test --workspace has no failure
that clean main does not show here
: with the whole branch stashed, lightcraft-engine --lib fails the same
20 sidecar fs-fault tests and lightcraft-ui-egui --lib the same denoise-model tests ("this build cannot run
denoise models"); nothing else fails. Those are platform/build-environment failures of main, not of this branch.

Three commits:

Related

Co-Authored-By: GLM 5.3 Flash noreply@z.ai

Fixes

Fixes #1225 (the issue tracking this failure).

The three as one story

mdlmarkham and others added 4 commits October 11, 2026 17:15
Three boolean expressions clippy now wants simplified (pipeline's
normalize_wb, engine's learn_as_shot_wb, per nonminimal_bool), a
descriptor_copy only its #[cfg(unix)] test calls (dead on Windows), and
desktop_entries_give_their_program is unix-gated (Path::is_absolute
decides by the platform, and desktop entries run there). None change
behaviour; all four fail cargo xtask ci on this toolchain from main.

Co-Authored-By: GLM 5.3 Flash <noreply@z.ai>
Co-Authored-By: GLM 5.3 Flash <noreply@z.ai>
…ip reads

The equivalence of `header_plan` / `preview_plan` broke for the corpus's
ARW6 pair: a Compression-32766 strip was holed behind its first 64 KiB
prefix, but the header probe validates more there - `parse_tile_header`
walks the 13 stream header words of every tile, `stream_halves` reads
each stream's index table, and `first_half_shift` decodes the residual
stream's first half, which sits behind the earlier streams' data. The
probe read zeros (and 0xFF) there and failed with "ARW6 first-half row
count outside 2..=7" where the whole file decodes (first corpus case:
arw6-sony-ilce7rm6-apsc-land-hq.arw; the corpus is git-ignored, so CI
never saw it).

`tiff_plan` now asks `arw6_keep` (crates/raw/src/sparse.rs) for those
scattered ranges when `image()` reports Compression 32766 for one strip:
the tile table, then per tile, in staged rounds so each ask sits in one
`Need`, the picture/group tables, the stream header words (positions
from the new `arw6::stream_header_positions`, mirroring the group-table
walk), then with the real `parse_tile_header` run, the 13 index tables
and finally each residual first half (its length A is its index's first
entry). A layout that cannot be walked - a corrupt ARW6 - reads whole:
`arw6::decode` stops at the same validation of loaded bytes, so the
probe is still identical. `parse_tile_table`/`parse_tile_header`/`u16_be`
/`u24_be` are now `pub(crate)` for the walker, and `Want::pending_plan`
(renamed from `into_plan`) takes `&mut self` so the walk can keep asking
after the IFD walk answered.

The full-size JPEG these files carry as a `JPEGInterchangeFormat` image
(compression 6/7, where 0x0201/0x0202 are the interchange tag and its
length and `image()` therefore declines) reached no hole at all and made
the plan read it whole: together with the strip work, the header plan
now reads 26-28% -> ARW corpus average 1.7% (the two ARW6 files read
2 / 1%); nothing reads the interchange image in header mode, and under
`preview_plan` `embedded_preview` wants it, so the hole is header-mode
only (the corpus test's 0 / 0xFF fills guard both).

Tests: without the corpus, sparse.rs's synthetic single- and two-tile
ARW6 files (residual stream past the prefix, Qis::REAL) assert the plan
reads past the 512 KiB prefix and probes as the whole file does, for
both fills; with it, `sparse_corpus` passes for both real files, both
fills, both plans, and the ARW6 decode-sum corpus tests are unchanged.
Gates: fmt, clippy -D warnings, heif, parity (+ refreshed summary),
layers, assets and wasm all pass; `cargo test --workspace` has no
failure that clean main doesn't show on this Windows machine (engine
sidecar's 20 fs-fault and ui-egui's denoise-model tests fail there
identically with the fix stashed).

Co-Authored-By: GLM 5.3 Flash <noreply@z.ai>
@mdlmarkham

Copy link
Copy Markdown
Contributor Author

Note for review: the middle ci: commit overlaps #1052 (“Windows: case-insensitive sidecar/rename fixes; Windows test and toolchain fixes”) — there, descriptor_copy is already gated to #[cfg(all(test, unix))] and desktop_entries_give_their_program is unix-gated; the boolean simplifications (normalize_wb, learn_as_shot_wb) are the only parts this branch carries that #1052 doesn't. Happy to drop the commit and rebase onto whichever lands first — the ARW6 fix in crates/raw/src/sparse.rs + crates/raw/src/vendor/arw6.rs is independent of it and is the subject here.

Two scoping facts so it doesn't read as a complete toolchain fix:

@wanikhawar wanikhawar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR also changes apps/lightcraft/src/editors.rs and contributors/people.toml, which have nothing to do with the ARW6 strip plan (rule 8). Please split them out. It also conflicts with main now.

@wanikhawar

Copy link
Copy Markdown
Contributor

#1477 already made ARW6 import describe from the whole file, and crates/raw/src/sparse.rs has since moved to craft-libs (#4244), so this can't rebase cleanly. It also carries unrelated test gating, lint rewrites and a contributors/people.toml entry (rule 8). If you still want the scattered-read plan, please propose it in craft-libs, and close this.

@FredApps

FredApps commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thank you @mdlmarkham. The ARW6 probe break was fixed on main by #1477, and crates/raw/src/sparse.rs has since moved to craft-libs (#4244), so this can no longer rebase. One thing did not land: the arw6_keep plan that keeps the probe's scattered strip reads instead of reading the whole file. If we still want that optimization it could be ported to craft-libs as its own PR, keeping your credit. Closing here.

@FredApps FredApps closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Header plan describes an ARW6 strip from part of it: the import probe fails where the whole file decodes

3 participants