r.lake: Reject seed coordinates north or west of the region - #7899
Open
Ady0333 wants to merge 1 commit into
Open
r.lake: Reject seed coordinates north or west of the region#7899Ady0333 wants to merge 1 commit into
Ady0333 wants to merge 1 commit into
Conversation
The conversion to a cell index truncated towards zero, so a coordinate less than one cell north or west of the region gave index 0 instead of a negative value and passed the check below zero. Such a seed was silently moved to the first row or column instead of being rejected.
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.
Follow up to #7877, which covers the southern and eastern bounds. This one covers the northern and western bounds, which have a different problem.
Problem
r.lakeconverts the seed coordinate to a cell index with a plain cast:The cast truncates towards zero, so every value between -1 and 0 becomes 0. A coordinate less than one cell north or west of the region therefore never reaches the check below zero. It is accepted and quietly used as row 0 or column 0, which is a cell the user did not ask for.
Going further out works, because at -1 and beyond the cast produces a negative value and the check catches it.
Reproduction
The second and third commands should print
Seed point outside the current regionand instead they fill the map.Fix
Floor the converted value so the interval between -1 and 0 stays negative and the existing check sees it. The northern and western edges themselves still map to row 0 and column 0, so seeds there keep working.
Tests
Four cases just outside the northern and western edges, which fail without the fix, and two cases on the edges themselves, which confirm valid seeds are still accepted.
Note that this touches
raster/r.lake/tests/r_lake_test.pyin the same place as #7877, so whichever merges second will need a small rebase.