Skip to content

fix: auto-discover ExifTool installed in subdirectories of trusted paths#1679

Open
octo-patch wants to merge 2 commits intomicrosoft:mainfrom
octo-patch:fix/issue-1660-exiftool-subdirectory-discovery
Open

fix: auto-discover ExifTool installed in subdirectories of trusted paths#1679
octo-patch wants to merge 2 commits intomicrosoft:mainfrom
octo-patch:fix/issue-1660-exiftool-subdirectory-discovery

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1660

Problem

When MarkItDown auto-discovers ExifTool via shutil.which("exiftool"), it verifies that the binary resides in a known trusted directory to prevent running arbitrary executables. The check used an exact directory comparison:

d == os.path.dirname(candidate)

However, a common Windows installation places ExifTool one level deeper than the trusted root, for example:

C:\Program Files\ExifTool\exiftool.exe

Here os.path.dirname(candidate) returns C:\Program Files\ExifTool, which does not equal the trusted entry C:\Program Files, so ExifTool is silently skipped. The user then gets metadata-lite image output with no error message explaining why.

Solution

Replace the exact-equality check with a two-part check:

candidate_dir == d or candidate_dir.startswith(d + os.sep)

This allows binaries installed in any subdirectory of a trusted root to be auto-discovered, while still rejecting paths outside the trusted roots (e.g. C:\Users\username\Downloads).

Additionally adds C:\Windows as a trusted root, since some users place ExifTool directly there.

Testing

  • Existing ExifTool tests continue to pass (exact directory case covered)
  • Verified path-matching logic manually for the subdirectory case:
    • C:\Program Files\ExifTool\exiftool.exe → trusted ✓
    • /opt/homebrew/Cellar/exiftool/12.90/bin/exiftool → trusted ✓
    • C:\Users\user\Downloads\exiftool.exe → not trusted ✓

octo-patch added 2 commits April 8, 2026 13:35
…icrosoft#1660)

Previously ExifTool was only auto-discovered if found directly in a trusted
directory (e.g. C:\Program Files). Common Windows installs place the binary
one level deeper (C:\Program Files\ExifTool\exiftool.exe), so dirname
returned a path that failed the exact-equality check and ExifTool was
silently not used.

Switch to startswith(d + os.sep) to allow subdirectory matches while keeping
the exact-match check, preserving the security boundary. Also add C:\Windows
as a trusted root since ExifTool is sometimes installed there directly.
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.

Should tell you when there is a missing dependency

1 participant