Guard landforms() against unbounded kernel allocations (#1302)#1304
Merged
Conversation
slope: clean (no findings) polygonize: MEDIUM only (Cat 1 missing memory guard, Cat 6 missing _validate_raster) sky_view_factor will land separately via PR #1300 (HIGH, Cat 1, fixed).
`landforms()` passed `inner_radius` and `outer_radius` straight into `_circular_kernel`, which allocates a (2r+1)^2 float64 array. With no upper bound, `outer_radius=20000` would request ~12.8 GB and `outer_radius=100000` would request ~320 GB. Add `_check_kernel_memory()` mirroring the convolution.py pattern and call it for both radii after the existing validation. Raises MemoryError before allocation when the kernel would exceed half of available RAM. Tests cover both inner_radius and outer_radius paths.
Contributor
Author
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Contributor
Done. Merged |
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
landforms()passedinner_radiusandouter_radiusstraight into_circular_kernel, which allocates a(2r+1)^2float64 array.outer_radius=20000requested ~12.8 GB;outer_radius=100000requested ~320 GB_check_kernel_memory()mirroring theconvolution.py:_check_kernel_memorypattern and calls it for both radii after the existing validationMemoryErrorbefore allocation when the kernel would exceed half of available RAMTest plan
pytest xrspatial/tests/test_terrain_metrics.py(194 passed)test_landforms_outer_radius_memory_guardchecksouter_radius=200000raisesMemoryErrortest_landforms_inner_radius_memory_guardchecksinner_radius=200000raisesMemoryError