fix: added asserts for total_num_variables >= point.len() check.#208
Merged
TomWambsgans merged 1 commit intoMay 1, 2026
Conversation
Contributor
Author
|
Hi @TomWambsgans, I have added the PR. Since you mentioned using |
Collaborator
|
thanks |
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
Fixes a potential integer underflow bug in
SparseStatement::selector_num_variables()where uncheckedusizesubtraction could silently wrap to a huge value in release builds, or panic in debug builds.Fix
Two targeted changes in
crates/whir/src/lib.rs:1. Assert the invariant at construction time in
new()andnew_next():2. Use
checked_subinselector_num_variables()as defense-in-depth:Note:
unique_value()anddense()are inherently safe becauseunique_valuealways uses an empty point (len = 0), anddensesetstotal_num_variables = point.len()exactly, therfore no assertion is needed there.Changes
crates/whir/src/lib.rs: Addassert!inSparseStatement::new()andSparseStatement::new_next(), usechecked_subinselector_num_variables()Testing
All
cargo runcommands meantioned in theREADMEare running properly.References
Fixes #182