Pentax MakerNote tags advertised with the wrong type, decoding their value raises a ValueError
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pyexiv2 |
Fix Released
|
Medium
|
Olivier Tilloy |
Bug Description
Traceback for pyexiv 0.3 below:
File "/usr/lib/
self.
File "/usr/lib/
self._value = self._convert_
File "/usr/lib/
return undefined_
File "/usr/lib/
return ''.join(map(lambda x: chr(int(x)), undefined.
File "/usr/lib/
return ''.join(map(lambda x: chr(int(x)), undefined.
ValueError: chr() arg not in range(256)
im = pyexiv2.
im.read()
for k in im.exif_keys:
s = im[k].value;
if s == 'Unknown':
s = im[k].raw_value # display raw value for unknown interpretations of the Exif value in exiv2 library
print "{0}: {1}".format(k,s)
Simplest fix is to mod the integer by 256, "e.g. int(x) % mod 256" before converting to a character and appending to a string. A more robust fix would translate or escape on all non-printable characters before outputing the character string. Suggested patches to follow..
Related branches
Changed in pyexiv2: | |
status: | Confirmed → In Progress |
Changed in pyexiv2: | |
milestone: | none → 0.3.1 |
Changed in pyexiv2: | |
status: | Fix Committed → Fix Released |
A ValueError raised in that case is intended, because the conversion fails.
The real issue is the root cause of this failure: the faulty tag is 'Exif.Pentax. PreviewResoluti on', and pyexiv2 thinks its type is 'Undefined', as advertised by the documentation (see http:// exiv2.org/ tags-pentax. html), where in fact it should be 'Short'.
It seems that exiv2 itself knows how to fix the type, because the command line tool returns the correct type:
$ exiv2 -PEkyvt IMGP1118sm.JPG | grep PreviewResolution PreviewResoluti on Short 640 480 640x480
Exif.Pentax.
This may very well be an issue with the way pyexiv2 queries libexiv2 for the type of a tag.