Skip to content

Add allocation guards to GPU read and VRT read paths#1196

Merged
brendancol merged 4 commits intomasterfrom
issue-1195
Apr 15, 2026
Merged

Add allocation guards to GPU read and VRT read paths#1196
brendancol merged 4 commits intomasterfrom
issue-1195

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1195.

Summary

  • read_geotiff_gpu() now calls _check_dimensions() before passing IFD dimensions to GPU decode functions
  • read_vrt() now calls _check_dimensions() before allocating the output array from VRT XML dimensions
  • open_geotiff, read_geotiff_gpu, and read_vrt accept a max_pixels kwarg, consistent with read_to_array

Both paths were missed by 521956a, which only guarded the CPU read functions.

Test plan

  • test_open_geotiff_max_pixels -- verifies max_pixels flows through open_geotiff to CPU reader
  • test_read_vrt_rejects_huge_dimensions -- VRT with 100k x 100k dims rejected
  • test_read_vrt_normal_size_ok -- 4x4 VRT passes guard
  • test_open_geotiff_vrt_max_pixels -- verifies max_pixels flows through open_geotiff to VRT reader
  • All 15 security tests pass; no regressions in geotiff test suite

Two security fixes for the geotiff subpackage:

1. Add a configurable max_pixels guard to read_to_array() and all
   internal read functions (_read_strips, _read_tiles, _read_cog_http).
   A crafted TIFF with fabricated header dimensions could previously
   trigger multi-TB allocations. The default limit is 1 billion pixels
   (~4 GB for float32 single-band), overridable via max_pixels kwarg.
   Fixes #1184.

2. Canonicalize VRT source filenames with os.path.realpath() after
   resolving relative paths. Previously, a VRT file with "../" in
   SourceFilename could read arbitrary files outside the VRT directory.
   Fixes #1185.
os.path.realpath() converts Unix-style paths to Windows paths on
Windows (e.g. /data/tile.tif becomes D:\data\tile.tif). Use
os.path.realpath() in the assertion so it matches the production
code's canonicalization on all platforms.
_check_dimensions() was added to CPU read paths in 521956a but missed
two allocation sites: read_geotiff_gpu() allocated from IFD dimensions
without a pixel limit, and read_vrt() allocated from VRT XML dimensions
without one. Both now call _check_dimensions() before allocating.
Adds max_pixels kwarg to open_geotiff, read_geotiff_gpu, and read_vrt
for consistency with read_to_array.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Apr 14, 2026
Resolve add/add conflict in test_security.py by keeping
the GPU-read and VRT allocation guard tests from this branch
alongside the base security tests that landed on master via #1189.
@brendancol brendancol merged commit 3339ea5 into master Apr 15, 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.

Unbounded allocation in GPU read and VRT read paths

1 participant