geotiff: raise on malformed IFD chain pointing past EOF (#1863)#1867
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
ValueErrorinparse_all_ifdsfor offsets>= len(data). - Update
TestClassicTIFFLargeOffsetto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_all_ifdsnow raisesValueErrorwhen an IFD chain offset points beyond the end of the file. The previous silentbreakcould mask corrupt overview metadata in truncated or malformed TIFFs.MAX_IFDSguard a few lines down.Test plan
next_ifd_offset >= len(data)raisesValueError.first_ifd_offset >= len(data)raisesValueError.next_ifd_offset == len(data)raises.next_ifd_offset == 0) still terminate cleanly.