Reject integer-dtyped input in perlin() (#1232)#1233
Merged
Conversation
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).
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
perlin()was silently corrupted (every pixel becameINT_MINon int32). The four backends write float noise into the buffer in place and then normalize byptp, which is zero once the floats cast to int.np.issubdtype(agg.dtype, np.floating)check inperlin()that raisesValueErrorbefore any mutation happens..claude/sweep-security-state.jsonwith 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 likefreq=(0, 0).Test plan
pytest xrspatial/tests/test_perlin.py -vpasses (12/12: 4 pre-existing, 8 new)ValueErrorwith a clear message instead of returning all-INT_MIN