Skip to content

Reject integer-dtyped input in perlin() (#1232)#1233

Merged
brendancol merged 1 commit into
masterfrom
issue-1232
Apr 23, 2026
Merged

Reject integer-dtyped input in perlin() (#1232)#1233
brendancol merged 1 commit into
masterfrom
issue-1232

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Fixes perlin() silently corrupts int-dtyped input rasters (all pixels -> INT_MIN) #1232: integer-dtyped input to perlin() was silently corrupted (every pixel became INT_MIN on int32). The four backends write float noise into the buffer in place and then normalize by ptp, which is zero once the floats cast to int.
  • Adds an np.issubdtype(agg.dtype, np.floating) check in perlin() that raises ValueError before any mutation happens.
  • Adds a parametrized regression test covering int8/int16/int32/int64 and uint8/uint16/uint32, plus a float64 sanity check alongside the existing float32 tests.
  • Updates .claude/sweep-security-state.json with the perlin sweep result and notes the remaining MEDIUM follow-up: the normalization step has no zero-ptp guard and still emits NaN for degenerate inputs like freq=(0, 0).

Test plan

  • pytest xrspatial/tests/test_perlin.py -v passes (12/12: 4 pre-existing, 8 new)
  • The reproduction from the issue now raises ValueError with a clear message instead of returning all-INT_MIN
  • float32 and float64 inputs still produce noise normalized to [0, 1]

perlin() writes float noise into the input buffer in place, then
normalizes by ptp.  With an integer buffer the float values cast to 0,
ptp ends up 0, and the div-by-zero produces NaN/Inf that casts back to
INT_MIN on every pixel -- a silently wrong result.

Add an np.issubdtype(agg.dtype, np.floating) check in perlin() that
raises ValueError, and a parametrized regression test covering int8
through uint32 plus a float64 sanity check.

Also records the perlin sweep result in
.claude/sweep-security-state.json, including the remaining MEDIUM
follow-up (no zero-ptp guard in the normalization step).
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 23, 2026
@brendancol brendancol merged commit eaf8e59 into master Apr 23, 2026
11 checks passed
@brendancol brendancol deleted the issue-1232 branch April 25, 2026 12:10
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.

perlin() silently corrupts int-dtyped input rasters (all pixels -> INT_MIN)

1 participant