Closed eigan closed 6 years ago
Good catch! Thank you for reporting this. It's definitely a bug in the library and not something you're doing wrong. (And thank you for the perfect bug report with a stack trace and repro example!)
It looks like the code handles empty result arrays fine, but doesn't handle null results where there is no array at all. The specific code where the problem lives is:
https://github.com/felixc/rexiv2/blob/d3988f7b6a2e10ddd5ac99d32855e54a5d17425d/src/lib.rs#L548-L563
The problem is that c_tags
is not confirmed to not be null before being dereferenced. Adding something like this should take care of it:
if c_tags.is_null() {
return Ok(tags);
}
Or possibly you might find it cleaner to update the loop conditional to
while !c_tags.is_null() && !(*c_tags.offset(cur_offset)).is_null() {
...but I don't know if the compiler is smart enough to not actually check that condition every loop, so maybe it's not optimal.
The same pattern appears in a few other places, e.g. lines 416, 449 and 480.
If you'd like to submit a patch, that's probably the fastest way to get you a fix immediately, and I'll cut a new release as soon as I can — otherwise I'll try to get a fixed version out this weekend.
Looks like what I wanted was to use the method get_tag_string
, which gives the expected result.
I applied your patch and it no longer crashes, but the value is Ok([])
, not sure if this is correct as the value from get_tag_string
is Ok("2016:01:10 13:27:20")
Edit: probably correct
Yup; I think the root cause of the confusion is that get_tag_multiple_strings
is meant to be used for metadata that represents a "collection" (e.g. Xmp.dc.creator, which is of type "XmpSeq").
The "Exif.Image.DateTime" used in this example isn't a sequence, but a single value — so it is correct that get_tag_multiple_strings
returns nothing but get_tag_string
does return a value. Or at least, it's using the gexiv2 API correctly, but maybe the API should be rethought to be less confusing.
I am learning Rust, so I might be doing something wrong.
image