Fix BoxedUint bitor-assign with wider rhs#1270
Open
tob-joe wants to merge 1 commit into
Open
Conversation
Grow the lhs limb buffer only when the rhs has greater precision, then OR the rhs limbs into the lhs in place. This preserves high rhs limbs without computing a full temporary BoxedUint result for every assignment. Add a regression covering a one-limb lhs OR-assigned with a two-limb max rhs. 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 #1270 +/- ##
=======================================
Coverage 90.99% 91.00%
=======================================
Files 189 189
Lines 22139 22151 +12
=======================================
+ Hits 20146 20158 +12
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
BoxedUintsupports mixed-precision bitwise OR by returning a result sized to the wider operand. TheBitOrAssign<&BoxedUint>implementation did not follow that behavior: it only ORed the overlapping limb prefix. If rhs had more limbs than lhs, the high rhs limbs were dropped.Fix
Grow the lhs limb buffer only when rhs is wider, padding new limbs with zero, then OR rhs limbs into lhs in place. Equal-width and narrower-rhs assignments do not allocate. Wider-rhs assignment replaces the boxed slice because
BoxedUintstores limbs as a fixed-lengthBox<[Limb]>.Tests
Added
bitor_assign_preserves_wider_rhs_limbs, which OR-assigns a one-limb lhs with a two-limb max rhs and checks that the assignment result matches non-assignment bitwise OR.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.