Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exiv2 -m file / exiv2 -M cannot handle whitespaces value #2836

Open
iblazhko opened this issue Nov 17, 2023 · 3 comments
Open

exiv2 -m file / exiv2 -M cannot handle whitespaces value #2836

iblazhko opened this issue Nov 17, 2023 · 3 comments
Labels

Comments

@iblazhko
Copy link

iblazhko commented Nov 17, 2023

Describe the bug

exiv2 -m file fails when value is filled with whitespaces.

To Reproduce

Create commands file metadata.txt with following content:

set Exif.Photo.Flash                             Short      0
set Exif.Photo.FocalLength                       Rational   350/10
set Exif.Photo.FocalLengthIn35mmFilm             Short      35
set Exif.Photo.LensSpecification                 Rational   350/10 350/10 140/100 140/100
set Exif.Photo.LensMake                          Ascii            
set Exif.Photo.LensModel                         Ascii      35mm f/1.4E

(note the whitespaces in Exif.Photo.LensMake line)

Try to apply this metadata to an image:

exiv2 -m metadata.txt image.jpg

Error:

metadata.txt, line 5: Invalid command line
exiv2: Error parsing -m option arguments
Usage: exiv2 [ option [ arg ] ]+ [ action ] file ...

Expected behavior

Specified value is applied as is, or an empty string is applied.

Desktop (please complete the following information):

  • OS and version: macOS 14.1.1 / arm64
  • Exiv2 version and source: exiv2 0.28.1 via Homebrew
  • Compiler and version: N/A
  • Compilation mode and/or compiler flags: N/A

Additional context

Can also be reproduced with exiv2 -M "set Exif.Photo.LensMake Ascii " image.jpg (note the space before closing ", exiv2 -M "set Exif.Photo.LensMake Ascii" image.jpg or exiv2 -M "set Exif.Photo.LensMake Ascii ''" image.jpg work fine).

Looks like a regression, I believe previous version was able to process same command, or maybe previous version trimmed -PVk -K output - I have a script I use to selectively copy Exif metadata, and noticed that it started to fail with some files I was able to process before.

@iblazhko iblazhko added the bug label Nov 17, 2023
@iblazhko
Copy link
Author

iblazhko commented Nov 19, 2023

In case this may be useful to someone having the same issue: as a workaround, I am piping exiv2 -PVk output through sed to trim trailing whitespaces, result can be processed by exiv2 -m-:

exiv2 -PVk \
  -K Exif.Image.DateTime \
  -K Exif.Image.Make \
  -K Exif.Image.Model \
  -K Exif.Photo.LensMake \
  -K Exif.Photo.LensModel \
  source.jpg \
| sed -e 's/[[:space:]]*$//' \
| exiv2 -m- target.jpg

@kamiccolo
Copy link
Contributor

kamiccolo commented Nov 20, 2023

I was about to state, that it may not be a bug, but rather a feature. But found this on the manual:

In the file, any blank lines or additional white space is ignored and any lines beginning with a # are comments.

Also, from the same manual:

value The remaining text on the line is the value, and can optionally be enclosed in quotes (see Quotations with 'modify' commands). For Ascii, XmpAlt, XmpBag, XmpSeq and XmpText, the value is optional which is equivalent to an empty value ("")

So, it's seams like expected behavior is not to differentiate between the following of examples You've provided:

exiv2 -M "set Exif.Photo.LensMake Ascii " image.jpg

exiv2 -M "set Exif.Photo.LensMake Ascii" image.jpg

Relevant (I guess) parts of the source:

  1. https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1234-L1257 (reading the lines)
  2. https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1302-L1426 (parsing the line)
  3. https://github.com/Exiv2/exiv2/blob/main/app/exiv2.cpp#L1363-L1405 (parsing the value, I guess the culprit is here)

@iblazhko
Copy link
Author

Thanks for confirming my assumptions.

Whatever the parsing rules are, I think it is a fair expectation that exiv2 -m should be able to consume what exiv2 -Pvk produces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants