-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Allow for IFDRational with negative numerator and zero denominator #8970
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?
Conversation
The proposed solution is functionally correct, but it requires developers to manually check the numerator and denominator each time. This introduces potential for inconsistency or error, especially if this behaviour needs to be checked on other parts of the code in the future. It seems the underlying issue, is that the code assumes IFDRational instances behave like floats and are directly comparable. That expectation is natural and intuitive, and likely why the bug slipped in when the previous change was committed. This made me think that it'd make more sense to align the behavior of IFDRational more closely with float semantics. A more mathematically consistent handling of division-by-zero cases would be:
If we go this route, and implement Does this approach make sense to you? I’d be happy to open a PR implementing the -inf/inf logic so you can review it in context. |
4c43e94
to
abf295f
Compare
abf295f
to
c8c6ff9
Compare
Ok, my next suggestion is I don't object to your idea, but Pillow tends to value backwards compatibility. The Pillow/src/PIL/TiffImagePlugin.py Lines 335 to 343 in 7e4d8e2
So there might be a preference to leave that as it is. I have to imagine that it is rare for IFDRationals with zero denominators to be checked for their sign, simply because it's taken this long for an issue to be raised about it. And since you discovered this problem from Pillow's internal use of the class, I have to imagine that external checks are rarer still. So, feel free to create a pull request with your suggestion, and see what others think. If you haven't thought of it already, another possibility would be changing |
I understand your point about backward compatibility and the existing docstring documentation for I’ve gone ahead and opened a new PR implementing the math.inf / -math.inf logic for zero denominators, as said before: #8978. Would be great if you could take a look when you have a chance. |
Resolves #8965. Alternative to #8966 and #8978
A user has found an image where the ExposureBiasValue signed rational TIFF tag has a negative numerator but a zero denominator.
When this is passed to our IFDRational, it is considered
nan
,Pillow/src/PIL/TiffImagePlugin.py
Lines 374 to 375 in 3c71559
which means it is not less than zero.
This means that it isn't detected as something to write as a signed rational.
Pillow/src/PIL/TiffImagePlugin.py
Lines 690 to 692 in 3c71559
This PR suggests replacing
v < 0
with(float(v.numerator) < 0) != (float(v.denominator) < 0)