Skip to content

Add metadata stripping for image loading and saving - #243

Merged
danoli3 merged 2 commits into
masterfrom
feat/metadata-stripping
Nov 1, 2026
Merged

danoli3 merged 2 commits into
masterfrom
feat/metadata-stripping

Conversation

@danoli3

@danoli3 danoli3 commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Closes #239.

Add FREEIMAGE_STRIP to load/save operations and FreeImage_StripMetadata() for existing bitmaps. The flag removes ICC profiles, EXIF, XMP, IPTC, comments, custom tags and thumbnails. Saving borrows the source pixels through a separate bitmap header, preserving the caller's metadata. Animation controls, transparency, palettes, resolution and the CMYK interpretation flag remain intact.

Use the sign bit rather than the proposed 0x100000: that value overlaps JPEG's scaled-load size field. Strip the flag before calling plugins, propagate the policy through nested and multipage operations with thread-local scope, and honor explicit JPEG_EXIFROTATE before removing orientation metadata. Document the public API and behavior in README and the changelog.

Security analysis: skip optional metadata readers where supported, including JPEG marker retention, PNG auxiliary chunks and TIFF/JXR metadata import. Codec libraries still parse container structures, and explicit EXIF rotation still needs EXIF parsing. Stripping an ICC profile does not convert the underlying colors.

The investigation also found that the TIFF bridge multiplied a byte-count IPTC field by four. Correct the field-type handling on read/write and add a 141-byte TIFF regression with a six-byte IPTC profile.

Validation on macOS arm64:

  • ASan Debug build: all 14 CTest suites pass, including the complete MainTestSuite.
  • Metadata regressions cover JPEG, PNG, TIFF, WebP and JXR round trips, in-place stripping, source preservation on failed saves, JPEG scaling/orientation, header-only loading, GIF animation/transparency, concurrent operations, local plugins and multipage TIFF.
  • The minimal TIFF triggers an ASan heap-buffer-overflow with the baseline TIFF bridge; the patched build reads its caption successfully without an ASan report.
  • Local configuration uses bundled codecs with OpenEXR, HEIF and JPEG XL disabled. Windows and optional HEIF/JXL validation are left to CI/review; no cross-platform runtime claim is made.

Add the FREEIMAGE_METADATA_STRIP CMake option, on by default. When it is
off, MetadataStrip.h replaces IsStrippingMetadata() and the strip scope
with constant inline stubs, so the plugin reader checks fold away, and
the thread-local state and CreateStrippedView are not built.
FreeImage_StripMetadata stays exported and returns FALSE, and
FREEIMAGE_STRIP is still masked out of plugin flags, so the ABI and
JPEG scaled-load bits are unchanged. Builds without CMake default to
enabled; pass -DFREEIMAGE_METADATA_STRIP=0 to opt out.

MetadataStripTest only builds when the option is on.
@danoli3
danoli3 force-pushed the feat/metadata-stripping branch from 7f80261 to 3064322 Compare November 1, 2026 00:27
@danoli3
danoli3 merged commit 73e756b into master Nov 1, 2026
136 of 138 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.

[Feature Request] Add a "strip" flag to ignore/remove all metadata (ICC, EXIF, XMP) during Load/Save

1 participant