Skip to content

terrain: scratch-buffer memory not guarded; lacunarity/persistence not validated #1443

@brendancol

Description

@brendancol

Description

Two MEDIUM-severity gaps in xrspatial.terrain.generate_terrain:

Cat 1 - scratch-buffer memory
_gen_terrain (numpy line 41) and _terrain_gpu (line 237) allocate 5-7 same-shape float32 scratch buffers (x/y meshgrid, warp_x/warp_y when warp_strength>0, weight in ridged mode, w_noise in worley mode, plus a tmp buffer on GPU) without a memory check. For a 30000x30000 caller-allocated template the marginal scratch footprint is ~14-28 GB on top of the ~7 GB output.

Cat 3 - scalar parameters
octaves is bounded >= 1 but lacunarity and persistence are not validated. lacunarity ** octaves overflows to inf for adversarial values; non-finite values silently propagate through the noise sum.

Expected behavior

  • numpy and cupy backends raise MemoryError when projected scratch memory exceeds 50% of available RAM/VRAM. Dask paths skip the guard since chunks are bounded.
  • lacunarity and persistence must be finite and positive.

Proposed fix

  • Add _check_memory(rows, cols) / _check_gpu_memory(rows, cols) helpers (24 B/pixel scratch budget) and call from _terrain_numpy / _terrain_cupy.
  • Add if not (np.isfinite(lacunarity) and lacunarity > 0) and same for persistence (allow persistence in (0, 1] semantically but the immediate concern is finite-and-positive).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messagesoomOut-of-memory risk with large datasets

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions