_read_value in xrspatial/geotiff/_header.py (around line 442) returns 0.0 when a RATIONAL or SRATIONAL value has a zero denominator. The SRATIONAL branch a few lines down does the same thing.
The rest of the geotiff reader fails closed on malformed input. See PR #2301 / commit f5fbad5 for the COG writer's actionable failure mode, and PR #2300 / commit 5e8bf9a which promoted the COG contract to stable. Quietly mapping a malformed rational to 0.0 is out of step with that. XResolution and YResolution can get silently altered, and the corrupted metadata then round-trips through the reader as if nothing happened.
Expected
A zero-denominator RATIONAL/SRATIONAL raises ValueError, with the tag name and the denominator in the message.
Actual
The value becomes 0.0. Two existing tests (TestReadValueRationals.test_rational_denominator_zero_returns_zero and test_srational_denominator_zero_returns_zero) pin this as expected behaviour, so they need to be updated alongside the fix.
Proposed fix
- Raise
ValueError in _read_value for zero denominators on both the RATIONAL and SRATIONAL branches.
- Pass the tag through so the error message can name it (e.g.
XResolution).
- Update the two existing tests to assert the new failure.
- Add a regression test that builds a TIFF with a zero-denominator
XResolution rational and confirms the public reader fails with an actionable message.
Acceptance
- Zero-denominator RATIONAL and SRATIONAL inputs raise
ValueError naming the tag and the denominator.
- The failure surfaces at the public read entry points, not just the internal helper.
- A regression test covers both paths.
_read_valueinxrspatial/geotiff/_header.py(around line 442) returns0.0when a RATIONAL or SRATIONAL value has a zero denominator. The SRATIONAL branch a few lines down does the same thing.The rest of the geotiff reader fails closed on malformed input. See PR #2301 / commit f5fbad5 for the COG writer's actionable failure mode, and PR #2300 / commit 5e8bf9a which promoted the COG contract to stable. Quietly mapping a malformed rational to
0.0is out of step with that.XResolutionandYResolutioncan get silently altered, and the corrupted metadata then round-trips through the reader as if nothing happened.Expected
A zero-denominator RATIONAL/SRATIONAL raises
ValueError, with the tag name and the denominator in the message.Actual
The value becomes
0.0. Two existing tests (TestReadValueRationals.test_rational_denominator_zero_returns_zeroandtest_srational_denominator_zero_returns_zero) pin this as expected behaviour, so they need to be updated alongside the fix.Proposed fix
ValueErrorin_read_valuefor zero denominators on both the RATIONAL and SRATIONAL branches.XResolution).XResolutionrational and confirms the public reader fails with an actionable message.Acceptance
ValueErrornaming the tag and the denominator.