Skip to content

Bound per-tile allocations in TIFF reader (#1215)#1216

Merged
brendancol merged 1 commit intomasterfrom
issue-1215
Apr 18, 2026
Merged

Bound per-tile allocations in TIFF reader (#1215)#1216
brendancol merged 1 commit intomasterfrom
issue-1215

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Fixes #1215.

The TIFF reader validates image dims but not tile dims. A TIFF with a 1x1 image and a 2^30 x 2^30 tile passes _check_dimensions and then makes the decompressor ask for terabytes. LZW does np.empty(expected_size); the GPU path does cupy.zeros(n_tiles * tile_bytes).

Changes

  • _read_tiles, _read_cog_http, and read_geotiff_gpu call _check_dimensions(tw, th, samples, max_pixels) after reading tile dims from the IFD.
  • Zero or negative tile dims raise ValueError before they can divide by zero in math.ceil(width / tw).
  • New test class TestTileDimensionGuard covers forged tile dims at the _read_tiles level and through open_geotiff, plus a check that real tile sizes still pass.
  • .claude/sweep-security-state.json records the audit.

Test plan

  • pytest xrspatial/geotiff/tests/test_security.py: 19 pass (13 existing, 4 new in the tile class, 2 VRT).
  • pytest xrspatial/geotiff/tests/: 435 pass. 3 failures in test_features.py::TestPalette are pre-existing (matplotlib deepcopy recursion); reproduce on master.

`_check_dimensions` validates image dims but not tile dims. A TIFF
claiming a 1x1 image with a 2^30 x 2^30 tile passes the guard and
then asks the decompressor for terabytes. LZW allocates an
`np.empty` of the claimed decompressed size, and the GPU path does
`cupy.zeros(n_tiles * tile_bytes)`.

Call `_check_dimensions` on the tile dims in `_read_tiles`,
`_read_cog_http`, and `read_geotiff_gpu`. Reject zero tile dims
before they reach the `math.ceil(width / tw)` division.

Tests forge tile dims both at the `_read_tiles` level and the
`open_geotiff` end-to-end level, and confirm real tile sizes (256,
512) still pass.

Also records the geotiff audit in `.claude/sweep-security-state.json`.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Apr 17, 2026
@brendancol brendancol merged commit 82204f7 into master Apr 18, 2026
11 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.

Security: unbounded allocation via TIFF tile dimensions (DoS)

1 participant