Skip to content

geotiff: raise on malformed IFD chain pointing past EOF (#1863)#1867

Merged
brendancol merged 1 commit into
mainfrom
issue-1863
May 14, 2026
Merged

geotiff: raise on malformed IFD chain pointing past EOF (#1863)#1867
brendancol merged 1 commit into
mainfrom
issue-1863

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Test plan

  • Malformed chain with next_ifd_offset >= len(data) raises ValueError.
  • Malformed file with first_ifd_offset >= len(data) raises ValueError.
  • Boundary case next_ifd_offset == len(data) raises.
  • Big-endian variant raises.
  • Valid chains (next_ifd_offset == 0) still terminate cleanly.
  • Existing IFD/header tests still pass (92 total in the sweep).

parse_all_ifds previously silently broke out of the chain walk when
next_ifd_offset >= len(data), masking truncated or corrupt overview
metadata. It now raises ValueError, matching the MAX_IFDS guard.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 14, 2026
@brendancol brendancol requested a review from Copilot May 14, 2026 18:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Replaces the silent break in parse_all_ifds with a ValueError when an IFD chain offset points past EOF, so malformed TIFFs are surfaced rather than masked as truncated-but-valid chains. Updates the existing related test and adds a dedicated test module.

Changes:

  • Raise ValueError in parse_all_ifds for offsets >= len(data).
  • Update TestClassicTIFFLargeOffset to expect the new exception.
  • Add comprehensive tests covering header first_ifd_offset, next_ifd_offset, boundary, big-endian, and valid-terminator cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
xrspatial/geotiff/_header.py Replace silent break with ValueError on past-EOF IFD offset
xrspatial/geotiff/tests/test_header.py Update existing test to expect ValueError
xrspatial/geotiff/tests/test_parse_all_ifds_malformed_chain_1863.py New tests covering malformed IFD chain scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brendancol brendancol merged commit fee5a16 into main May 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geotiff: parse_all_ifds silently truncates IFD chains pointing past EOF

2 participants