Repository navigation
v.class: Fix out-of-bounds read when no records are selected - #7692
Merged
Merged
Conversation
An empty WHERE result left an empty data array, which the classification algorithms then indexed at data[0] and data[count - 1]. The values printed as class breaks were whatever the heap happened to hold, which is zeroed on Linux but not on Windows, making the test flaky there. Warn and keep the zero-initialized breaks when nothing is selected, and reject an empty array in AS_class_apply_algorithm.
wenzeslaus
approved these changes
Jul 14, 2026
wenzeslaus
left a comment
Member
There was a problem hiding this comment.
Change to make valid but "zero" output on empty selection makes sense for the tool.
I have some doubts about using warning for no selection, but @petrasovaa says it is appropriate given the context (unlike e.g. for v.db.select).
I assume more work in the library would be needed to do something else than fatal at this point.
wenzeslaus
enabled auto-merge (squash)
July 14, 2026 09:05
echoix
pushed a commit
to wenzeslaus/grass
that referenced
this pull request
Jul 14, 2026
) An empty WHERE result left an empty data array, which the classification algorithms then indexed at data[0] and data[count - 1]. The values printed as class breaks were whatever the heap happened to hold, which is zeroed on Linux but not on Windows, making the test flaky there. Warn the user and keep the zero-initialized breaks when nothing is selected, and reject an empty array in AS_class_apply_algorithm.
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.
Context
test_v_class_where_no_matchesfails intermittently on Windows CI but passes on Linux. It is not a flaky test: it was asserting on the contents of uninitialized memory.When the
whereclause selects no records,nrecis 0, so v.class hands an empty array to the classification library, which readsdata[0]anddata[count - 1]:The printed breaks were whatever the heap held. Linux zeroes fresh heap pages, so they came out as
0.0and the test passed; Windows reuses dirty memory, so sometimes not.Change
v.class keeps its behavior (warning, zeroed breaks, exit 0) but now produces it deliberately: with no records it skips the classification and stats calls, leaving the zero-initialized breaks and frequencies in place.
AS_class_apply_algorithmalso rejects an empty array, removing the same latent bug in d.vect.thematic.Commit message
An empty WHERE result left an empty data array, which the classification
algorithms then indexed at data[0] and data[count - 1]. The values printed
as class breaks were whatever the heap happened to hold, which is zeroed
on Linux but not on Windows, making the test flaky there.
Warn the user and keep the zero-initialized breaks when nothing is selected, and
reject an empty array in AS_class_apply_algorithm.