Skip to content

Add memory guards to reproject CuPy paths and output grid#1188

Merged
brendancol merged 1 commit intomasterfrom
security-reproject-1186-1187
Apr 13, 2026
Merged

Add memory guards to reproject CuPy paths and output grid#1188
brendancol merged 1 commit intomasterfrom
security-reproject-1186-1187

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Add _MAX_WINDOW_PIXELS guard to _reproject_chunk_cupy() and _reproject_dask_cupy(), matching the existing guard in the numpy path. Without this, a degenerate projection near a singularity could attempt to load the entire source raster onto the GPU for a single chunk, causing GPU OOM.
  • Add _MAX_OUTPUT_PIXELS guard (1 billion pixels) in _compute_output_grid() that rejects output grids with unreasonable dimensions. Without this, a tiny resolution parameter on a large extent triggers uncontrolled memory allocation.
  • Add tests for both guards.

Fixes #1186, fixes #1187.

Test plan

  • test_output_grid_too_large_raises -- verifies ValueError for extreme resolution
  • test_output_grid_normal_resolution_ok -- verifies normal grids pass
  • test_numpy_chunk_source_window_guard -- verifies basic reproject still works
  • Full test suite: pytest xrspatial/tests/test_reproject.py -- 96 passed

The numpy reproject path had a _MAX_WINDOW_PIXELS guard that caps the
source window fetched for each output chunk, preventing OOM when a
degenerate projection maps a small output chunk to a huge source area.
The CuPy paths were missing this guard.

Also adds a _MAX_OUTPUT_PIXELS guard in _compute_output_grid that
rejects output grids exceeding 1 billion pixels, preventing a
denial-of-service via tiny resolution values on large extents.

Fixes #1186, fixes #1187.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Apr 13, 2026
@brendancol brendancol merged commit bc2d9c0 into master Apr 13, 2026
11 checks passed
@brendancol brendancol mentioned this pull request Apr 13, 2026
4 tasks
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.

No upper bound on output grid dimensions in _compute_output_grid Missing source-window size guard in CuPy reproject paths

1 participant