Fix unsound unchecked indexing in RootMoveList and Stack::offset#167
Merged
chase-manning merged 2 commits intomainfrom Feb 22, 2026
Merged
Fix unsound unchecked indexing in RootMoveList and Stack::offset#167chase-manning merged 2 commits intomainfrom
chase-manning merged 2 commits intomainfrom
Conversation
- Replace unsafe get_unchecked_mut with safe indexing in insert_score_depth and insert_score, which provides automatic bounds checking via the existing IndexMut trait implementation - Add debug_assert bounds check and safety documentation to Stack::offset - Add tests verifying out-of-bounds panics for insert_score_depth and insert_score Co-authored-by: chase-manning <53957795+chase-manning@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unsoundness in insert_score_depth and insert_score functions
Fix unsound unchecked indexing in RootMoveList and Stack::offset
Feb 22, 2026
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.
insert_score_depthandinsert_scoreuseget_unchecked_mutwithout bounds validation, allowing UB on out-of-bounds index.Stack::offsetperforms raw pointer arithmetic with no safety checks.Changes
RootMoveList::insert_score_depth/insert_score: Replaceunsafe { self.get_unchecked_mut(index) }with safe&mut self[index], leveraging the existingIndexMutimpl which bounds-checks through slice indexingStack::offset: Adddebug_assert!on offset magnitude and document safety invariants for callers#[should_panic]tests for out-of-bounds access on both methodsOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.