Skip to content

fix(xmp): handle near-limit XMP spill to Extended XMP, add fuzzer and fixture coverage - #494

Merged
DichenZhang1 merged 1 commit into
feat/preserve-xmp-metadatafrom
polish/preserve-xmp-metadata
Oct 2, 2026
Merged

DichenZhang1 merged 1 commit into
feat/preserve-xmp-metadatafrom
polish/preserve-xmp-metadata

Conversation

@DichenZhang1

Copy link
Copy Markdown
Collaborator

Summary

Follow-up polish on top of feat/preserve-xmp-metadata (09a3936) covering the near-limit Standard XMP spill boundary, duplicate #ifdef cleanup, fuzzer coverage, and real-world Apple gain-map fixture tests.

Changes

  1. Near-Limit Standard XMP (~64.9 KB – 65,503 B) Spill to Extended XMP (lib/src/jpegr.cpp, lib/src/ultrahdr_api.cpp):

    • In JpegR::appendGainMap, when kWriteXmpMetadata (-DUHDR_WRITE_XMP=ON) is active and merging the Ultra HDR Container:Directory into a standard-sized user XMP packet (<= 65,503 bytes) pushes xmp_primary_str over kMaxStandardXmpPayload (65,503 bytes), revert xmp_primary_str to the unmerged user_xmp_str and spill it cleanly into Extended XMP chunks while writing only the Ultra HDR primary XMP + xmpNote:HasExtendedXMP GUID into the Standard XMP segment (preventing duplicate Container:Directory entries in Extended XMP).
    • Unify xmpAllowance in uhdr_encode (kJpegAppSegmentTotalMaxBytes + xmp_sz + num_chunks * 79) so near-limit standard XMP packets that spill into Extended XMP never overflow the output buffer.
  2. Header Include Cleanup (lib/src/ultrahdr_api.cpp):

    • Remove the duplicate #ifdef UHDR_ENABLE_HEIF #include block.
  3. Fuzzer Coverage (fuzzer/ultrahdr_dec_fuzzer.cpp, fuzzer/ultrahdr_enc_fuzzer.cpp):

    • Exercise uhdr_strip_gain_map (two-pass size query + strip) and uhdr_dec_get_xmp in both fuzzers without changing FuzzedDataProvider consumption order.
  4. Unit Tests (tests/ultrahdr_api_test.cpp):

    • UltraHdrApiTest.StripGainMapOnAppleGainMapFixtures: Verifies uhdr_strip_gain_map on apple_gainmap_new.jpg and apple_gainmap_old.jpg (including DRI and RST0..RST7 markers in the primary scan).
    • UltraHdrApiTest.NearLimitStandardXmpSpillsCleanlyToExtendedXmp: Verifies a 65,200-byte user XMP packet spills cleanly to Extended XMP in -DUHDR_WRITE_XMP=ON mode and round-trips through uhdr_dec_get_xmp and uhdr_strip_gain_map.

Test Plan

  • Verified ultrahdr_unit_test in both -DUHDR_WRITE_XMP=ON -DUHDR_WRITE_ISO=ON (26/26 UltraHdrApiTest, 34/34 JpegRTest, 17/17 JpegDecoderHelperTest) and -DUHDR_WRITE_XMP=OFF -DUHDR_WRITE_ISO=ON (21/21 UltraHdrApiTest).

@DichenZhang1
DichenZhang1 merged commit 259f3ed into feat/preserve-xmp-metadata Oct 2, 2026
65 checks passed
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.

1 participant