Skip to content

Extract full-resolution JPEG previews from CR3 files - #9541

Open
wilx wants to merge 40 commits into
Exiv2:mainfrom
wilx:fix-cr3-full-preview
Open

wilx wants to merge 40 commits into
Exiv2:mainfrom
wilx:fix-cr3-full-preview

Conversation

@wilx

@wilx wilx commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #2854.

Stacked on #9527 and depends on its shared BMFF infrastructure. This PR includes those prerequisite commits until #9527 is merged; the CR3 change is the final commit.

Extract the full-resolution JPEG from ordinary single-sample CR3 CRAW/JPEG tracks through the existing preview API and CLI. Preserve THMB/PRVW and stop CR3 previews accumulating on repeated reads or structure printing. CR3 remains read-only.

Local Linux validation: full serial debug CTest 8/8; focused debug, no-XMP, ASan/UBSan and Meson tests; BMFF-disabled/video-disabled builds; 30-second preview fuzzing. Extracted JPEGs from real RAW/C-RAW samples match ExifTool byte-for-byte. Sanitizer/fuzz validation disabled optional network support to avoid an external library startup leak.

AI assistance: OpenAI Codex assisted with implementation, tests and documentation and ran local validation.

Comment thread src/bmffbox_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
Comment thread src/heifwrite_int.cpp Fixed
@wilx
wilx force-pushed the fix-cr3-full-preview branch 4 times, most recently from e5e47a1 to 8d2ea37 Compare November 4, 2026 23:34
wilx added 25 commits November 22, 2026 16:23
Represent boxes, item locations, references, and properties as checked
ranges in seekable input without copying encoded image payloads. Retain
all item IDs and extents, including file-relative and idat-relative data.

Bound structural work and reject malformed addressing and relationships.
Keep write eligibility separate so opaque content can be inspected while
unsupported layouts are rejected before future rewriting. Register the
private model in CMake and Meson; leave production writing disabled.
Add 41 synthetic and corpus cases covering supported field widths and
versions, references, properties, shared ranges, malformed boundaries,
resource limits, I/O failures, and an 8 GiB sparse input. Check real HEIF
and AVIF fixtures against expectations from an independent inventory.

Verify that deferred formats and unsafe layouts are rejected and that
production metadata writing remains disabled. Register the tests in
CMake and Meson, linking the private library for Meson unit tests.
Rebuild item tables and relocate streamed payload ranges while removing
obsolete primary metadata, unused media bytes, and padding. Reject shared
metadata edits, ambiguous XMP MIME types, and unsupported relocation before
writing, then verify the prepared output.

Related to Exiv2#2349. This private engine adds no image codec dependency.
Register supported HEIF files through a private BmffImage subclass. Use
fresh metadata serialization and compact rewriting for primary Exif/XMP
updates and removal, with byte-identical no-ops and preservation checks.

Keep AVIF, CR3, and JPEG XL writing disabled. Prepare local file output on
disk before transfer; final replacement retains the existing BasicIo
failure contract and is not atomic.

Related to Exiv2#2349.
Exercise compact rewriting, public metadata APIs, and CLI operations with
synthetic containers and existing HEIF fixtures. Check obsolete-byte
absence, repeated edits, retained payloads, large offsets, and failures.

Related to Exiv2#2349.
Keep MIME and embedded XMP packets available during Exif edits without
the XMP toolkit. Reject structured edits and ambiguous packet merges,
while allowing explicit raw replacement and removal. Clear cached raw
packets with structured XMP data to avoid restoring removed metadata.
Exercise raw packet preservation, replacement, embedded XMP promotion
and physical removal. Check rejection of ambiguous packet merges and
structured edits. Use raw packets for applicable feature-disabled tests
and skip only cases that require structured XMP decoding.
Index metadata keys while keeping ordered values. Preserve last-item
precedence and duplicate Exif tags within the winning item without
repeatedly scanning every previously decoded tag.
Check that the last item replaces a duplicate tag group while retaining
unrelated fields and both duplicate values from the winning item.
Extend both read/write fuzz drivers with deterministic Exif updates and
metadata clears, followed by a reread. This exercises serialization and
compaction in addition to unchanged writes on owned MemIo inputs.
Update format capabilities and document supported layouts, physical
metadata removal, shared-data rejection, feature-disabled behavior and
final-transfer limitations. Explain factory selection of the writer.

Related to Exiv2#2349; CR3 writing remains outside this HEIF change.
Describe shared structures, field coordinates, parsing limits and payload
ownership. Document parser and write-eligibility interfaces.
Describe parser helpers and separate boundary, resource-budget and item
graph checks with comments and spacing.
Explain preserve/remove/replace requests, stream ownership and positioning,
allocation limits and prepared-output failure handling.
Describe range ownership, shared-data rejection, layout promotion and
prepared-output verification. Separate the main rewriting steps.
Describe factory ownership and probe positioning without promising that
a recognized container supports metadata writing.
Describe metadata precedence, embedded XMP handling, fresh serialization
and staging lifetime. Clarify cleanup intent and final-transfer limits.
Explain fixture layouts, I/O doubles, mutations and preservation checks.
Separate setup, editing and assertions without changing test behavior.
Describe disposable fixtures, metadata round trips, obsolete-byte checks
and staging or destination failures. Separate the edit sequences.
Describe helper inputs and error propagation, and explain how metadata
mutation exercises serialization, compaction and the subsequent reread.
Keep the merged embedded XMP when an unrelated Exif field changes.
Honor explicit raw-packet edits and verify regenerated packets through
their decoded properties.
Clear all buffered metadata before invoking the legacy reader while
retaining the narrower semantics of explicit HEIF metadata clears.
Delegate MIME reporting to the successful legacy reader and reset that
choice when adopting native metadata.
wilx added 15 commits November 22, 2026 16:23
Initialize XMLPacket and Canon AFInfo keys once on first use and reuse
them for lookups. Keep string conversion outside metadata scan loops.
Move checked box headers, bounded cursors and read budgets into a private
format-independent reader. Route the HEIF item parser through it without
changing item validation or write eligibility.

Add generic container tests and register the new code with CMake and Meson.
Extract a reusable item model and parser with explicit limits and format
policy hooks. Keep HEIF admission, metadata selection, Canon handling and
relocation rules in a dedicated adapter.

Rename the HEIF-specific writer and update both build systems and tests.
Separate box measurement, placement, relocation maps and bounded I/O from
HEIF edit policy. Keep iloc encoding and layout convergence in the item
layer, with HEIF retaining range ownership and metadata verification.

Register the private layers in CMake and Meson and add focused layout,
relocation, header-promotion and I/O regressions.
Use a private adapter for legacy metadata decoding and structure output,
retaining format-specific behavior and the existing BmffImage ABI.
Share counted traversal and FullBox field decoding with the item parser.

Reject malformed UUID and container boundaries and propagate structural
I/O failures. Add compatibility and hardening regressions.
Describe shared box, item and output mechanics and their format adapters.
Link the internal guide from the focused testing documentation.
Resolve the source buffer range before taking the destination end iterator. This avoids GCC 15 bounds warnings caused by argument evaluation order in the two failing vector insertions.
Replace the nine annotated subscript expressions with at(), preserving the existing bounds guards and unflagged accesses.
Separate embedded XMP decoding from error enforcement to avoid incorrect argument passing in MSVC x86 Debug builds. Normalize CRLF output in the HEIF CLI test helper.

Validated with MSVC 19.44 x86 Debug: 518 unit tests passed with five expected skips; three HEIF CLI tests passed with one expected POSIX-only skip.
Probe whether directory and file write restrictions are enforced before testing those failure paths. Split the checks so an unsupported staging restriction does not skip destination-open coverage.

Validated the original false failure and corrected permission checks with the local CLI; the HEIF regression file passes with expected platform skips.
Give the full unit-test executable a bounded 120-second timeout. In
PR Exiv2#9531, macOS sanitizer and FreeBSD VM jobs passed the large Exif
boundary cases but exhausted Meson's 30-second default during later
XMP concurrency tests. Retain every test and assertion.

Validated the registered timeout change and unchanged limits for other
test groups. All 400 unit tests passed on MSVC x86 Debug forcefallback,
including the 35 focused JPEG/EXV tests. Native platform checks await CI.

(cherry picked from commit 1ef5e05)
Resolve single-sample BMFF tables and Canon CRAW/JPEG descriptions through
the shared box reader. Expose the embedded JPEG alongside THMB/PRVW using
the existing native preview API.

Rebuild CR3 preview state on metadata reads and keep structure printing
from accumulating duplicate entries.

Fixes Exiv2#2854.
Normalize CRLF in the captured textual listing before comparison. Keep extracted JPEG and source-preservation checks byte exact.

Validated with MSVC 19.44 x86 Debug: the CR3 CLI regressions pass, the inherited HEIF CLI tests pass with expected skips, and the full unit-test suite passes.
@wilx
wilx force-pushed the fix-cr3-full-preview branch from 8d2ea37 to cc366c3 Compare November 22, 2026 15:24
@mergify

mergify Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.45781% with 238 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.36%. Comparing base (32c380d) to head (cc366c3).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/heifimage_int.cpp 85.09% 31 Missing and 38 partials ⚠️
src/bmffimage.cpp 81.54% 28 Missing and 22 partials ⚠️
src/heifwrite_int.cpp 88.21% 9 Missing and 30 partials ⚠️
src/cr3preview_int.cpp 83.09% 7 Missing and 17 partials ⚠️
src/bmffitem_int.cpp 94.00% 5 Missing and 13 partials ⚠️
src/heifstructure_int.cpp 90.11% 5 Missing and 12 partials ⚠️
src/bmffsample_int.cpp 87.93% 2 Missing and 5 partials ⚠️
src/bmfflayout_int.cpp 95.83% 1 Missing and 5 partials ⚠️
src/bmffitemwrite_int.cpp 94.73% 1 Missing and 3 partials ⚠️
src/bmffbox_int.cpp 96.20% 1 Missing and 2 partials ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9541      +/-   ##
==========================================
+ Coverage   65.28%   67.36%   +2.08%     
==========================================
  Files         117      129      +12     
  Lines       21859    23681    +1822     
  Branches    10806    11780     +974     
==========================================
+ Hits        14270    15953    +1683     
- Misses       5324     5336      +12     
- Partials     2265     2392     +127     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

please add CR3(BMFF) "CRAW" read support to get bigger preview image

2 participants