Enforce UintRef slice length checks in release builds#1272
Open
tob-joe wants to merge 1 commit into
Open
Conversation
Use assert! instead of debug_assert! for UintRef slice-copy length checks so mismatched lengths keep the documented panic behavior in optimized builds. Add release-mode regression tests for copy_from_slice and conditional_copy_from_slice with longer source slices. Co-authored-by: GPT 5.5 <gpt-5.5@openai.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1272 +/- ##
=======================================
Coverage 90.99% 91.00%
=======================================
Files 189 189
Lines 22139 22147 +8
=======================================
+ Hits 20146 20154 +8
Misses 1993 1993 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
UintRef::copy_from_slicedocuments that it panics whenself.nlimbs() != limbs.len(), but the check useddebug_assert!, so optimized builds did not enforce that contract:crypto-bigint/src/uint/ref_type/slice.rs
Lines 25 to 33 in 4c6f87d
UintRef::conditional_copy_from_slicehas the same runtime length check pattern and its# Panicsdocs also state a limb-count mismatch panic, though the current wording saysrhs.nlimbs()despite taking a limb slice:crypto-bigint/src/uint/ref_type/slice.rs
Lines 41 to 48 in 4c6f87d
Fix
Use
assert!for both length checks so debug and release builds preserve the documented panic behavior.Tests
Added regression tests for mismatched lengths in both slice-copy APIs and verified them in release mode:
This work was completed by Trail of Bits as part of the Patch The Planet project in collaboration with OpenAI. The issue was identified primarily by the Codex coding agent, and manually reviewed before submission.