Bound per-tile allocations in TIFF reader (#1215)#1216
Open
brendancol wants to merge 1 commit intomasterfrom
Open
Bound per-tile allocations in TIFF reader (#1215)#1216brendancol wants to merge 1 commit intomasterfrom
brendancol wants to merge 1 commit intomasterfrom
Conversation
`_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`.
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
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_dimensionsand then makes the decompressor ask for terabytes. LZW doesnp.empty(expected_size); the GPU path doescupy.zeros(n_tiles * tile_bytes).Changes
_read_tiles,_read_cog_http, andread_geotiff_gpucall_check_dimensions(tw, th, samples, max_pixels)after reading tile dims from the IFD.ValueErrorbefore they can divide by zero inmath.ceil(width / tw).TestTileDimensionGuardcovers forged tile dims at the_read_tileslevel and throughopen_geotiff, plus a check that real tile sizes still pass..claude/sweep-security-state.jsonrecords 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 intest_features.py::TestPaletteare pre-existing (matplotlib deepcopy recursion); reproduce on master.