Skip to content

Detect and correct incorrect makernote offsets#730

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/detect-incorrect-makernote-offsets
Draft

Detect and correct incorrect makernote offsets#730
Copilot wants to merge 2 commits into
mainfrom
copilot/detect-incorrect-makernote-offsets

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Some cameras write makernote tag value offsets relative to the makernote's own start position rather than the TIFF header, causing tag data to be read from wrong positions. This mirrors the ExifTool warning: "Possibly incorrect maker notes offsets (fix by N?)".

Algorithm (ExifTiffHandler.determineBestBase)

Inspired by ExifTool's FixBase heuristic:

  1. Find the minimum raw offset value among IFD tags with external data (byteCount > 4)
  2. Compute the expected minimum for both the TIFF-header base and the makernote-relative base — where "expected minimum" = IFD end position − base
  3. Return the base whose expected minimum is closest to the observed minimum
  4. If the makernote base wins, add a warning to the directory
"Possibly incorrect makernote offsets; using makernote base instead of TIFF header base (difference: N)"

Coverage

All 17 TiffReader.processIfd calls in processMakernote that previously passed tiffHeaderOffset directly now route through determineBestBase(ifdOffset, tiffHeaderOffset, makernoteOffset, reader), covering:

  • Canon, Casio (types 1 & 2), DJI, Kyocera, Leica (Camera AG & LEICA brand), Minolta, Nikon (type 1 & plain), Olympus (OLYMP\0/Epson/Agfa), Panasonic, Samsung, Sigma/Foveon, Sony (types 1 & 6)

Makernotes that already explicitly use the makernote-relative base (Olympus OLYMPUS\0II, OM SYSTEM, Nikon type 2 embedded TIFF, Fujifilm, Pentax, Sanyo, Ricoh, Apple iOS, Leica type 5) are unaffected.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repository.sonatype.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/metadata-extractor/metadata-extractor org.codehaus.plexus.classworlds.launcher.Launcher test -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
Implements detection of makernotes where tag value offsets are written
relative to the makernote's own start instead of the TIFF header, similar
to ExifTool's 'Possibly incorrect maker notes offsets' warning.

The algorithm (inspired by ExifTool's FixBase) finds the minimum raw offset
among external-data IFD tags and compares it to the expected minimum for
both the standard TIFF-header base and the makernote-relative base. If the
makernote base matches better, it is used and a warning is added to the
directory.

All 17 processMakernote branches that used tiffHeaderOffset directly now
call determineBestBase() to pick the correct offset base. A new unit test
verifies both the warning message and the tag value extraction for the
Canon makernote with incorrect offsets.

Closes #654

Agent-Logs-Url: https://github.com/drewnoakes/metadata-extractor/sessions/5a5ddde7-5eb5-49a6-8c8b-5bb07682439b

Co-authored-by: drewnoakes <350947+drewnoakes@users.noreply.github.com>
Copilot AI changed the title [WIP] Add detection and fixing of incorrect makernote offsets Detect and correct incorrect makernote offsets Apr 22, 2026
Copilot AI requested a review from drewnoakes April 22, 2026 13:39
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.

Detect incorrect makernote offsets

2 participants