Skip to content

Reject zero-denominator RATIONAL/SRATIONAL values in TIFF header reader #2313

@brendancol

Description

@brendancol

_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions