Closed hfiguiere closed 1 year ago
Hmm that's very strange... When I test with a file/buffer that doesn't have the tag set at all, I correctly get None
, thanks to the boolean return value from gexiv2, which the code was already checking.
I'd like to land this patch anyway since it's a robustness improvement in the case of some malformed data.
Do you have a reproducible test case that triggers this? Is it possible the tag is in fact set, but somehow set with a 0 denominator?
Here's what I'm working with (using the raw-tag-access
feature for lower-level comparison):
let minipng = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0,
1, 0, 0, 0, 1, 8, 0, 0, 0, 0, 58, 126, 155, 85, 0, 0, 0, 10, 73, 68, 65,
84, 8, 215, 99, 248, 15, 0, 1, 1, 1, 0, 27, 182, 238, 86, 0, 0, 0, 0, 73,
69, 78, 68, 174, 66, 96, 130];
let meta = rexiv2::Metadata::new_from_buffer(&minipng).unwrap();
assert_eq!(meta.get_tag_raw("Exif.Photo.MaxApertureValue"), Err(rexiv2::Rexiv2Error::NoValue));
assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), None);
let ratio = num_rational::Ratio::new_raw(16, 10);
meta.set_tag_rational("Exif.Photo.MaxApertureValue", &ratio);
assert_eq!(meta.get_tag_raw("Exif.Photo.MaxApertureValue"), Ok(vec![0, 0, 0, 16, 0, 0, 0, 10]));
assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), Some(ratio));
meta.clear_tag("Exif.Photo.MaxApertureValue");
assert_eq!(meta.get_tag_raw("Exif.Photo.MaxApertureValue"), Err(rexiv2::Rexiv2Error::NoValue));
assert_eq!(meta.get_tag_rational("Exif.Photo.MaxApertureValue"), None);
EDIT: I think I'm unable to create a failing test case, since Exiv2 won't allow setting a rational field with a 0 denominator.
Base: 68.67% // Head: 68.63% // Decreases project coverage by -0.04%
:warning:
Coverage data is based on head (
9e72f6e
) compared to base (ff52e16
). Patch coverage: 66.66% of modified lines in pull request are covered.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
I think it's from a "generated" exif from gphoto2 querying the EXIF from a RAW file.
Now the 0
denominator WILL happen whatever. It's not a "if" but a "when". I'll see about getting a data sample.
Thanks for the context! I merged this and the fix is included in the new 0.10 release that I just pushed out.
If you have a data sample handy, that would still be useful for adding a test for this case. Cheers!
This happen if the tag doesn't exist.
(the tag doesn't exist)