Skip to content

Conversation

@Saphereye
Copy link

@Saphereye Saphereye commented Nov 29, 2025

Fixes #149448

This PR fixes a potential integer overflow while calculating the children of a node for a BinaryHeap for zero sized types.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Comment on lines +803 to +807
// Recompute guarded left child for new hole position.
child = match hole.pos().checked_mul(2).and_then(|x| x.checked_add(1)) {
Some(idx) => idx,
None => return hole.pos(),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the change would needlessly obfuscate this unsafe code. Under what conditions can the multiply overflow? (Note that the increment definitely can't.)

Both of the patched functions are structured similarly, and could be restructured to only do the let mut child = 2 * hole.pos() + 1; after checking the loop condition in a way that avoids the overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BinaryHeap integer overflow with ZST?

4 participants