Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b033e51
[bmff] Add a bounded item-based container model
wilx Oct 9, 2026
32f3808
[tests] Cover BMFF item model preservation and rejection
wilx Oct 9, 2026
22eb0f2
[bmff] Add compact HEIF container rewriting
wilx Oct 9, 2026
369c377
[heif] Enable native Exif and XMP metadata editing
wilx Oct 9, 2026
d1f5daf
[tests] Cover HEIF writing and physical metadata removal
wilx Oct 9, 2026
ecfbe15
[heif] Preserve raw XMP when the toolkit is disabled
wilx Oct 9, 2026
9a63a3a
[tests] Cover HEIF writing without the XMP toolkit
wilx Oct 9, 2026
c46208c
[heif] Avoid repeated scans when merging metadata items
wilx Oct 9, 2026
8494814
[tests] Verify duplicate Exif group precedence across HEIF items
wilx Oct 9, 2026
e0bbc9f
[fuzz] Exercise HEIF metadata edits and compaction
wilx Oct 9, 2026
0cbbe1d
[docs] Describe HEIF metadata writing and its limits
wilx Oct 9, 2026
2e07feb
[docs] Document the internal BMFF model and parser contract
wilx Oct 9, 2026
0a3cc07
[docs] Explain BMFF parsing and validation steps
wilx Oct 9, 2026
4466566
[docs] Document BMFF rewrite and item-reader contracts
wilx Oct 9, 2026
9cd746d
[docs] Explain BMFF metadata rewriting and verification
wilx Oct 9, 2026
c7964e4
[docs] Document the internal HEIF factory and type probe
wilx Oct 9, 2026
e4be78e
[docs] Explain HEIF metadata editing and transfer steps
wilx Oct 9, 2026
25f9079
[tests] Document BMFF and HEIF test intent
wilx Oct 9, 2026
98d967a
[tests] Explain HEIF CLI edit and failure regressions
wilx Oct 9, 2026
16fe150
[fuzz] Document HEIF metadata edit coverage
wilx Oct 9, 2026
a1a0c61
[heif] Preserve raw XMP when copying metadata without the toolkit
wilx Oct 10, 2026
152d171
[heif] Restore legacy Adobe UUID XMP reading
wilx Oct 10, 2026
894d26a
[heif] Preserve merged embedded XMP during Exif edits
wilx Oct 10, 2026
ef05527
[heif] Clear buffered metadata before legacy fallback reads
wilx Oct 10, 2026
a3acc07
[heif] Retain MIME types after legacy fallback reads
wilx Oct 10, 2026
5d3173b
[heif] Reuse parsed Exif keys for metadata lookups
wilx Oct 10, 2026
d6e68ca
[docs] Document HEIF writing APIs, tests and fuzzing
wilx Oct 10, 2026
555e424
[bmff] Extract shared box reader and traversal
wilx Oct 10, 2026
68f889f
[bmff] Separate standard item mechanics from HEIF policy
wilx Oct 10, 2026
27fbe17
[bmff] Extract generic output layout and item relocation
wilx Oct 10, 2026
1ba5bca
[bmff] Migrate legacy reader to shared box traversal
wilx Oct 10, 2026
cc9b899
[bmff] Document internal layers and ownership contracts
wilx Oct 10, 2026
9a8b959
[bmff] Avoid GCC bounds warnings in TIFF test fixtures
wilx Oct 31, 2026
4af5c57
[bmff] Use checked access at CodeQL-reported locations
wilx Oct 31, 2026
9c08599
[bmff] Fix MSVC HEIF test failures
wilx Oct 31, 2026
3c934b4
Raise the minimum supported GCC version to 10
wilx Oct 31, 2026
e4585d5
[tests] Respect filesystem permissions in HEIF failure tests
wilx Oct 31, 2026
c649dfa
Allow more time for Meson unit tests on slow CI runners
wilx Oct 31, 2026
4d9b7ed
[cr3] Extract full-resolution JPEG previews
wilx Oct 18, 2026
cc366c3
[tests] Normalize CR3 preview listing newlines
wilx Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/on_PR_meson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Linux-GCC${{matrix.cxx}}-deps=${{matrix.deps}}
strategy:
matrix:
cxx: ['9', '16']
cxx: ['10', '16']
deps: ['enabled', 'disabled']
steps:
- uses: actions/checkout@v7
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The file ReadMe.txt in a build bundle describes how to install the library on th

# Building, Installing, Using and Uninstalling Exiv2

You need [CMake](https://cmake.org/download/) to configure the Exiv2 project, any C++ compiler implementing the C++ 20 standard and the associated tool chain.
You need [CMake](https://cmake.org/download/) to configure the Exiv2 project, any C++ compiler implementing the C++ 20 standard and the associated tool chain. When building with GCC, version 10 or newer is required.

<div id="B_I_U_Unix">

Expand Down Expand Up @@ -826,6 +826,17 @@ This is discussed: [https://github.com/Exiv2/exiv2/issues/1230](https://github.c

Access to the BMFF code is guarded by the CMake option: `-DEXIV2_ENABLE_BMFF=ON` (enabled by default).

Existing item-based HEIF/HEIC files support primary-image Exif and XMP writing,
including growth, replacement and removal. The native writer preserves encoded
image payloads and compacts obsolete metadata storage without an image codec
dependency. AVIF, CR3 and JPEG XL writing remain unsupported. Unsupported layouts
and edits conflicting with shared item data are rejected before source transfer.

See [HEIF and HEIC metadata writing](exiv2.md#heif-and-heic-metadata-writing) for
the supported structures, metadata-removal scope, build options and transfer
failure limitations. Use `ImageFactory::open()` to obtain the HEIF writer; the
factory reports `ImageType::heif`, while the general `BmffImage` remains read-only.

[TOC](#TOC)
<div id="LicenseSupport">

Expand Down
50 changes: 48 additions & 2 deletions exiv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ DNG | Read/Write | Read/Write | Read/Write | - | Read/Write | Rea
EPS | - | - | Read/Write | | - | -
EXV | Read/Write | Read/Write | Read/Write | Read/Write | Read/Write | Read/Write
GIF | - | - | - | - | - | -
HEIC | Read | Read | Read | - | - | Read
HEIF | Read | Read | Read | - | - | Read
HEIC | Read/Write | Read | Read/Write | - | Read | Read
HEIF | Read/Write | Read | Read/Write | - | Read | Read
JP2 | Read/Write | Read/Write | Read/Write | - | Read/Write | Read/Write
JPEG | Read/Write | Read/Write | Read/Write | Read/Write | Read/Write | Read/Write
JXL | Read | Read | Read | - | - | Read
Expand Down Expand Up @@ -121,6 +121,52 @@ and see if `enable_bmff=1`.
rudimentary support to read metadata from quicktime, matroska and riff based video files (e.g.
.MOV/.MP4, .MKV, .AVI, .WAV, .ASF).

### HEIF and HEIC metadata writing

With BMFF support enabled, Exiv2 can add, replace and remove Exif and XMP for
the primary image of an existing item-based HEIF/HEIC file. This includes
growing and shortening values, deleting individual tags, clearing a category,
and extracting/reinserting metadata through `.exv` files. Encoded images are
copied without decoding or recompression; no image codec library is required.

Writing supports the `heic`, `heix` and `mif1` major brands, self-contained
`mdat` and `idat` item storage, and primary coded or derived images (including
grids). Thumbnails, auxiliary images, other image items, their properties,
and ICC profiles are preserved. Capability reporting describes potential
operations; each write checks the actual container before changing the source.
AVIF, CR3 and JPEG XL writing remain unsupported. Timed sequences, protected
items, external data references, item construction method 2, compressed XMP,
and unknown structures whose offsets cannot be safely relocated are rejected.
Creating a new HEIF image, editing ICC profiles, and standalone IPTC changes
are unsupported. Embedded IPTC is preserved during unrelated Exif edits.

Changed metadata is serialized afresh and the output is compacted. Successful
deletion or replacement removes the targeted obsolete metadata payloads and
unused storage from the new file, including shortened/deleted TIFF values,
old media gaps and padding. If those bytes are also required by another item,
the edit is rejected before source replacement. Independent active metadata
belonging to other images remains. This operation does not erase backups,
older copies, filesystem history or information encoded in image pixels.
An explicit clear performs cleanup even when the decoded category is empty;
an unchanged write with no pending cleanup preserves the file byte for byte.

Exif byte order is retained. Known MakerNotes and embedded thumbnail data are
reconstructed and checked for preservation; unsupported serialization changes
fail before transfer. Canon autofocus fields derived from `AFInfo` are read-only.
Repeated edits do not accumulate superseded payloads or duplicate image data.

Without the XMP toolkit, Exif edits and raw XMP packet preservation, replacement
and removal remain available. Structured XMP edits and Exif edits that require
merging distinct primary XMP packets need the toolkit and are rejected without
it. An explicit XMP replacement or clear can replace those packets together.

Structural parsing and metadata sizes are bounded independently of image size.
Limits include 16 MiB of parsed structural data, 65,536 items, 100,000 boxes,
16 levels of nesting, and 64 MiB of combined Exif/XMP input payloads. Large
encoded image ranges are copied in bounded chunks. Local file writes prepare
and validate a temporary file before transfer; failure before transfer leaves
the source unchanged. A failure or crash during final transfer can leave an
incomplete destination. Replacement is not guaranteed to be atomic.

[TOC](#TOC)

Expand Down
42 changes: 42 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,48 @@ Alternatively, a simple script is provided for running the fuzzer in a continuou
../fuzz/fuzzloop.sh
```

### HEIF metadata writing

Both `fuzz-read-write` and `fuzz-read-print-write` exercise HEIF edits after
their initial unchanged write. The input size modulo four selects an Exif
description update, Exif removal, XMP removal, or removal of both categories.
After a successful edit, the result is read again through the public image API.

For a focused run, build with BMFF support and Clang's sanitizers. From the
repository root, with the [build dependencies](../README.md#dependencies)
installed:

```bash
cmake -S . -B build-heif-fuzz -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DEXIV2_ENABLE_BMFF=ON -DEXIV2_BUILD_FUZZ_TESTS=ON \
-DEXIV2_TEAM_USE_SANITIZERS=ON
cmake --build build-heif-fuzz --parallel 4 \
--target fuzz-read-write fuzz-read-print-write
```

The following existing fixtures select all four edit operations. Copy them
into the build directory and use a separate writable corpus for each target.
The 2 MiB input limit accommodates these HEIF seeds, including files larger
than the limits in the general examples. Each target runs for about 30 seconds.

```bash
(
set -e
cd build-heif-fuzz
mkdir -p heif-seeds
cp ../test/data/Canon.HIF ../test/data/Stonehenge.heic \
../test/data/heic.heic ../test/data/issue_9292_sony_8_left-bottom.HIF heif-seeds/
for target in fuzz-read-write fuzz-read-print-write; do
mkdir -p "heif-corpus-$target"
LSAN_OPTIONS=suppressions=../fuzz/knownleaks.txt \
"./bin/$target" "heif-corpus-$target" heif-seeds \
-dict=../fuzz/exiv2.dict -max_len=2097152 -max_total_time=30 \
-timeout=10 -rss_limit_mb=2048 -artifact_prefix="heif-corpus-$target/"
done
)
```

## Generating a dictionary

Fuzzers perform better with a [dictionary](https://llvm.org/docs/LibFuzzer.html#dictionaries). For example, suppose the code contains a condition like [this](https://github.com/Exiv2/exiv2/blob/15098f4ef50cc721ad0018218acab2ff06e60beb/src/xmpsidecar.cpp#L177-L179):
Expand Down
41 changes: 41 additions & 0 deletions fuzz/fuzz-heif-write.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef FUZZ_HEIF_WRITE_HPP
#define FUZZ_HEIF_WRITE_HPP

#include <exiv2/exiv2.hpp>

/*!
@brief Exercise HEIF serialization and compaction after the drivers' unchanged write.
@param image Image backed by the fuzz driver's owned MemIo; other image types are ignored.
@param selector Select an Exif update or metadata removal deterministically from input size.

A successful write is read back to exercise the emitted container. Exceptions
propagate to the fuzz driver's existing invalid-input handler.
*/
inline void fuzzHeifWrite(Exiv2::Image& image, size_t selector) {
if (image.imageType() != Exiv2::ImageType::heif)
return;

// Mutate metadata so valid seeds reach the rewrite path rather than only a no-op.
switch (selector % 4) {
case 0:
image.exifData()["Exif.Image.ImageDescription"] = "HEIF fuzz metadata";
break;
case 1:
image.clearExifData();
break;
case 2:
image.clearXmpData();
break;
case 3:
image.clearMetadata();
break;
}

// Parse the result through the public API as well as exercising its serialization.
image.writeMetadata();
image.readMetadata();
}

#endif
3 changes: 3 additions & 0 deletions fuzz/fuzz-read-print-write.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <exiv2/exiv2.hpp>

#include "fuzz-heif-write.hpp"

#include <cassert>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -44,6 +46,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
image->printStructure(buffer, Exiv2::kpsIptcErase);

image->writeMetadata();
fuzzHeifWrite(*image, size);

} catch (...) {
// Exiv2 throws an exception if the metadata is invalid.
Expand Down
3 changes: 3 additions & 0 deletions fuzz/fuzz-read-write.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <exiv2/exiv2.hpp>

#include "fuzz-heif-write.hpp"

#include <cassert>
#include <iomanip>
#include <iostream>
Expand All @@ -15,6 +17,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

image->readMetadata();
image->writeMetadata();
fuzzHeifWrite(*image, size);

} catch (...) {
// Exiv2 throws an exception if the metadata is invalid.
Expand Down
13 changes: 13 additions & 0 deletions include/exiv2/bmffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace Exiv2 {

#ifdef EXV_ENABLE_BMFF
namespace Exiv2 {
namespace Internal {
//! @brief Private adapter for legacy metadata interpretation over shared box traversal.
class BmffLegacyReader;
} // namespace Internal

struct Iloc {
explicit Iloc(uint32_t ID = 0, uint32_t start = 0, uint32_t length = 0) : ID_(ID), start_(start), length_(length) {
}
Expand All @@ -36,6 +41,12 @@ struct Iloc {

/*!
@brief Class to access BMFF images.

This general BMFF class provides read access. Use ImageFactory::open() for
HEIF/HEIC editing: the factory selects a private specialization and reports
ImageType::heif. Its Exif/XMP write capability is subject to validation of the
file's item layout; unsupported layouts fail before source replacement.
Direct construction of BmffImage does not enable HEIF writing.
*/
class EXIV2API BmffImage : public Image {
public:
Expand Down Expand Up @@ -117,6 +128,8 @@ class EXIV2API BmffImage : public Image {
static constexpr Exiv2::ByteOrder endian_{Exiv2::bigEndian};

private:
friend class Internal::BmffLegacyReader;

void openOrThrow() const;
/*!
@brief recursiveBoxHandler
Expand Down
13 changes: 13 additions & 0 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ class EXIV2API Image {
/*!
@brief Returns the access mode, i.e., the metadata functions, which
this image supports for the metadata type \em metadataId.
@note This reports format capabilities. writeMetadata() validates the
particular file layout and requested edits, and may reject an operation
even when write access is reported.
@param metadataId The metadata identifier.
@return Access mode for the requested image type and metadata identifier.
*/
Expand Down Expand Up @@ -541,6 +544,13 @@ using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
@brief Returns an Image instance of the specified type.

The factory is implemented as a static class.

@note With BMFF support enabled, HEIF/HEIC files recognized by the HEIF probe
report ImageType::heif. open() returns a private HEIF implementation with
Exif/XMP writing support, subject to validation of the file's layout and
requested edits. Direct construction of BmffImage retains its read-only
behavior; use this factory to obtain HEIF writing support.
@see BmffImage
*/
class EXIV2API ImageFactory {
friend bool Image::good() const;
Expand Down Expand Up @@ -673,6 +683,9 @@ class EXIV2API ImageFactory {
/*!
@brief Returns the access mode or supported metadata functions for an
image type and a metadata type.
@note This reports format capabilities, without inspecting a file.
Image::writeMetadata() validates the particular file layout and requested
edits, and may reject an operation even when write access is reported.
@param type The image type.
@param metadataId The metadata identifier.
@return Access mode for the requested image type and metadata identifier.
Expand Down
1 change: 1 addition & 0 deletions include/exiv2/image_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class ImageType {
qtime,
riff,
mkv,
heif, //!< Item-based HEIF/HEIC; writing depends on the file layout.
};
} // namespace Exiv2

Expand Down
18 changes: 18 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_library(
exiv2lib_int OBJECT
bmffbox_int.cpp
bmffbox_int.hpp
bmffsample_int.cpp
bmffsample_int.hpp
cr3preview_int.cpp
cr3preview_int.hpp
bmffitem_int.cpp
bmffitem_int.hpp
bmffitemwrite_int.cpp
bmffitemwrite_int.hpp
bmfflayout_int.cpp
bmfflayout_int.hpp
heifstructure_int.cpp
heifstructure_int.hpp
heifwrite_int.cpp
heifwrite_int.hpp
canonmn_int.cpp
canonmn_int.hpp
casiomn_int.cpp
Expand Down Expand Up @@ -105,6 +121,8 @@ add_library(
asfvideo.cpp
basicio.cpp
bmffimage.cpp
heifimage_int.cpp
heifimage_int.hpp
bmpimage.cpp
convert.cpp
cr2image.cpp
Expand Down
Loading
Loading