Skip to content

Fix overflow panic draining an empty tree with integer coordinates - #246

Merged
adamreichold merged 1 commit into
georust:masterfrom
MaxFreedomPollard:fix-drain-empty-tree-overflow
Sep 11, 2026
Merged

adamreichold merged 1 commit into
georust:masterfrom
MaxFreedomPollard:fix-drain-empty-tree-overflow

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
  • I agree to follow the project's code of conduct.
  • I added an entry to the project's change log file if knowledge of this change could be valuable to users.

drain_within_distance panicked with an arithmetic overflow on an empty tree with integer coordinates, because the removal function was handed the empty root envelope whose corners are the scalar type's maximum and minimum. The drain iterator now seeds its stack only when the root has children, matching the guard SelectionIterator::new already has. test_drain_within_distance_on_empty_tree covers a tree that was never filled and one emptied by removals, and it fails with the overflow if the guard is removed.

@adamreichold

Copy link
Copy Markdown
Member

This should not be necessary during every iteration step but only during iterator construction as the pathological AABB with only be forced upon the user by us for an empty tree as described in #184, in any other case the supplied coordinates were pathological to begin with.

Also please don't post uselessly verbose LLM-generated PR descriptions. Everything that is meant to communicate with humans like us maintainers should be written by them.

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor Author

I'm sorry it's verbose, noted for this repo.

@michaelkirk michaelkirk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix LGTM, thanks!

I have a non-blocking concern about the documentation, but happy to merge either way.

Comment thread rstar/src/algorithm/removal.rs Resolved
`RTree::drain_within_distance` panicked with "attempt to multiply with overflow" whenever the tree was empty and the coordinate type was an integer,
because the root of an empty tree carries `AABB::new_empty()`, whose lower corner is `Scalar::max_value()` and whose upper corner is `Scalar::min_value()`.

The query side already guards against this in `SelectionIterator::new`, `SelectionIteratorMut::new`, `select_nodes` and `select_nodes_mut` by testing `!root.children.is_empty()` first, added in #184 to fix #161.
@adamreichold
adamreichold force-pushed the fix-drain-empty-tree-overflow branch from 86a1f34 to c08c410 Compare September 11, 2026 09:34
@adamreichold
adamreichold added this pull request to the merge queue Sep 11, 2026
Merged via the queue into georust:master with commit a40d83b Sep 11, 2026
6 checks passed
adamreichold pushed a commit that referenced this pull request Nov 1, 2026
)

- [x] I agree to follow the project's [code of
conduct](https://github.com/georust/.github/blob/main/CODE_OF_CONDUCT.md).
- [x] I added an entry to the project's change log file if knowledge of
this change could be valuable to users.
---

`drain_within_distance` panicked with an arithmetic overflow on an empty
tree with integer coordinates, because the removal function was handed
the empty root envelope whose corners are the scalar type's maximum and
minimum. The drain iterator now seeds its stack only when the root has
children, matching the guard `SelectionIterator::new` already has.
`test_drain_within_distance_on_empty_tree` covers a tree that was never
filled and one emptied by removals, and it fails with the overflow if
the guard is removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants