Skip to content

exiftool: paths with spaces or shell characters are passed to the shell unquoted #329

Description

@thc1006

rawtoaces main at 868a571, Ubuntu 24.04, gcc 13.3, exiftool 12.76.

perform_exiftool_call (src/rawtoaces_util/exiftool.cpp) builds the exiftool command line by string concatenation and hands it to popen(), with neither the exiftool path nor the image path quoted:

std::string command = exiftool_path + " -S";
...
command += " " + image_path;

So a space or a shell character in either path breaks the call. I tried four cases with BatteryPark.NEF copied around (small program calling fetch_metadata with cameraMake / cameraModel):

image path without space                 -> OK   make='NIKON CORPORATION'
image path with spaces                   -> OK   make=''
exiftool path with a space               -> FAIL  Failed to execute exiftool. Please make sure that its locati
image name with $ and ()                 -> FAIL  Failed to execute exiftool. Please make sure that its locati

with exiftool complaining on stderr for the second one:

Error: File not found - /tmp/dir
Error: File not found - with
Error: File not found - space/Battery
Error: File not found - Park.NEF

The second case is the bad one: the shell splits the path into four file names, exiftool prints "File not found" for each, but the call still counts as successful because stdout is not empty (FileName is printed for the fragments), so fetch_metadata returns true with no metadata and the lens correction later reports the camera make as missing. Nothing points at the space in the path.

On Windows the same applies to C:\Program Files\... for the binary, and (1) in a file name is what every browser download produces.

I'll send a PR that quotes both paths (single quotes for sh, double quotes for cmd.exe with the extra outer pair cmd needs) and adds a test with a dir with spaces/Battery Park (1).NEF copy of the fixture.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions