← Back to team overview

pyexiv2-developers team mailing list archive

Re: Null bytes in strings

 

Hi Damon & all,

On 2010-06-05, Damon Lynch <damonlynch@xxxxxxxxx> wrote:
>> [...]
>>    
> The problem occurs in files that have been edited and had their EXIF
> data messed up by poorly written programs. In the file a user of Rapid
> Photo Downloader sent me, the values for camera manufacturer and camera
> model had two null bytes at the end of each string, and two extraneous
> regular characters. There is obviously nothing we can do about the
> extraneous regular characters, but the null bytes are a different case.

I'va had a look at the file you sent me (for reference, the value of the
'Exif.Image.Make' tag is 'NIKON CORPORATION\x00e\x00s'). It looks like a
poorly written program has been writing unwanted trash at the end of the
tag indeed.
You mentioned that interestingly, eog displays the value correctly (I
can confirm). I haven't read eog's code, but it's quite likely because
of the null character itself. The value must be sprintf'd somewhere, so
the tail of the value after the first null byte is truncated, which has
the fortunate side effect that we can observe.

> Other similar problems can pop up. One I have seen is where the editing
> program has changed the format in the date fields.

Yeah, this is quite annoying. As a result when parsing a date[time] in
pyexiv2, I have to cope with quite a number of formats that don't comply
with the specification. Makes you wonder how hard it is to read a
specification and implement it properly...
However for this kind of issue, the following trick should do:

   metadata[key].value = metadata[key].value

(not tested, but it should overwrite the tag's value with its own value,
thus reformatting the raw value according to the specification).

> This make me wonder if a "sanity check" utility function might be a
> useful addition to pyexiv2.

It probably would be quite useful. Do you have suggestions of how the
API could look like?

> I will send Olivier offlist a couple of example files.
> 
> Damon

Cheers,

Olivier



References