Value.__str__ doesn't translate Exiv2::Error into a Python exception. If the value's text can't be converted to UTF-8, str() terminates the whole interpreter and there is no way to catch it from Python:
import exiv2
v = exiv2.CommentValue()
v.read(b"UNICODE\x00A") # UserComment charset header + odd-length (invalid UTF-16) payload
str(v)
iconv: Invalid argument (errno = 22) inbytesleft = 1
after which the process aborts (exit 0xC0000409 on Windows, SIGABRT on macOS).
The same conversion through v.toString() raises a normal exiv2.Exiv2Error (kerInvalidIconvEncoding), which is what I'd expect from str() too.
This is reachable with ordinary files: some early-2000s cameras stored UCS-2 UserComments, e.g. https://commons.wikimedia.org/wiki/File:Bernhard_Richter.jpg (Kodak DX3500). Reading that file's metadata and calling str(datum.value()) aborts with "Cannot convert text encoding from 'UCS-2LE' to 'UTF-8'". We hit this in iscc-sdk through exactly that pattern and worked around it by switching to Metadatum.toString() (iscc/iscc-sdk#159). str() is also easy to call by accident via print(), logging or f-strings.
python-exiv2 0.18.1, libexiv2 0.28.8, Python 3.12, seen on Windows and macOS. The repro uses the deprecated bytes read() for brevity; values read from a real file behave the same.
Value.__str__doesn't translateExiv2::Errorinto a Python exception. If the value's text can't be converted to UTF-8,str()terminates the whole interpreter and there is no way to catch it from Python:after which the process aborts (exit 0xC0000409 on Windows, SIGABRT on macOS).
The same conversion through
v.toString()raises a normalexiv2.Exiv2Error(kerInvalidIconvEncoding), which is what I'd expect fromstr()too.This is reachable with ordinary files: some early-2000s cameras stored UCS-2 UserComments, e.g. https://commons.wikimedia.org/wiki/File:Bernhard_Richter.jpg (Kodak DX3500). Reading that file's metadata and calling
str(datum.value())aborts with "Cannot convert text encoding from 'UCS-2LE' to 'UTF-8'". We hit this in iscc-sdk through exactly that pattern and worked around it by switching toMetadatum.toString()(iscc/iscc-sdk#159).str()is also easy to call by accident via print(), logging or f-strings.python-exiv2 0.18.1, libexiv2 0.28.8, Python 3.12, seen on Windows and macOS. The repro uses the deprecated bytes
read()for brevity; values read from a real file behave the same.