-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Set tag type accordingly if IFDRational with 0 denominator #8966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Set tag type accordingly if IFDRational with 0 denominator #8966
Conversation
ecfae11
to
3ac0420
Compare
Clarification regarding:
This change in behavior is due to how >>> float('nan') == float('nan')
False
>>> float('nan') > 0
False
>>> float('nan') < 0
False
>>> float('nan') == 0
False Before commit 5ff2027, the logic used self.tagtype[tag] = (
TiffTags.RATIONAL
if all(v >= 0 for v in values)
else TiffTags.SIGNED_RATIONAL
) After the commit, the logic was changed to inspect values individually: for v in values:
assert isinstance(v, IFDRational)
if v < 0:
self.tagtype[tag] = TiffTags.SIGNED_RATIONAL
break
else:
self.tagtype[tag] = TiffTags.RATIONAL This change means that when a value is |
for more information, see https://pre-commit.ci
Co-authored-by: Andrew Murray <[email protected]>
Co-authored-by: Andrew Murray <[email protected]>
Fixes #8965. Alternative to #8970 and #8978
Changes proposed in this pull request:
__float__
method in IFDRationalAfter investigating the issue, I found that the EXIF tag contains the value (-1, 0), which results in
float('nan')
via the IFDRational class. This was previously handled more gracefully, but starting from commit 5ff2027 (included in Pillow 11.1.0), all NaN IFDRational values are considered as TiffTags.RATIONAL.This causes a problem when the writer attempts to serialize these values using write_rational, which fails because
struct.pack("2L", ...)
cannot handle negative values. In such cases, write_signed_rational should be used instead.