Skip to content

Reject all-zero rasters in mesh_utils.create_triangulation (#1378)#1381

Merged
brendancol merged 1 commit intomainfrom
issue-1378
Apr 30, 2026
Merged

Reject all-zero rasters in mesh_utils.create_triangulation (#1378)#1381
brendancol merged 1 commit intomainfrom
issue-1378

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

@brendancol brendancol commented Apr 30, 2026

Summary

  • Guard create_triangulation() against the divide-by-zero / divide-by-NaN that produced garbage mesh geometry on all-zero or all-NaN cupy rasters
  • The guard runs before any hash or device-buffer work and raises ValueError with the offending max value in the message
  • 5 unit tests cover all-zero, all-NaN, all-negative, single-positive-pixel, and the error-message format

Fixes #1378. Deferred Cat 3 finding from the gpu_rtx security audit (#1308 / PR #1310).

Why ValueError instead of a sentinel scale

A raster with no positive elevation has no terrain to triangulate. Substituting scale = 1.0 would still hand the OptiX raytracer a flat mesh and produce garbage hillshade / viewshed output. Raising matches the _validate_raster style used elsewhere in xrspatial.

Test plan

  • pytest xrspatial/tests/test_gpu_rtx_mesh.py -v -- 5 new tests pass
  • pytest xrspatial/tests/test_gpu_rtx_memory.py -v -- 9 existing tests still pass (4 RTX-gated end-to-end included)
  • pytest xrspatial/tests/test_hillshade.py xrspatial/tests/test_viewshed.py -- 81 tests pass

create_triangulation() computed scale = max(H, W) / cupy.amax(raster.data)
without checking that the max was positive and finite. An all-zero raster
gave scale = inf and an all-NaN raster gave scale = nan, both of which
propagated into vertex z-coordinates and produced garbage geometry that
the OptiX raytracer would silently render.

Add a guard that raises ValueError when maxH is non-finite or non-positive,
before any hash or device-buffer work. This is the deferred Cat 3 finding
from the gpu_rtx security audit (#1308 / PR #1310).

Tests cover the all-zero, all-NaN, all-negative, and single-positive-pixel
cases plus the error-message format.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 30, 2026
@brendancol brendancol merged commit 1e2dfcc into main Apr 30, 2026
10 of 11 checks passed
@brendancol brendancol deleted the issue-1378 branch May 4, 2026 19:50
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.

mesh_utils: divide-by-zero on all-zero raster in create_triangulation

1 participant