Skip to content

Fix BoxedUint bitor-assign with wider rhs#1270

Open
tob-joe wants to merge 1 commit into
RustCrypto:masterfrom
tob-joe:fix-boxeduint-bitorassign-widening
Open

Fix BoxedUint bitor-assign with wider rhs#1270
tob-joe wants to merge 1 commit into
RustCrypto:masterfrom
tob-joe:fix-boxeduint-bitorassign-widening

Conversation

@tob-joe
Copy link
Copy Markdown

@tob-joe tob-joe commented Jun 4, 2026

Summary

BoxedUint supports mixed-precision bitwise OR by returning a result sized to the wider operand. The BitOrAssign<&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 BoxedUint stores limbs as a fixed-length Box<[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.

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
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.00%. Comparing base (4c6f87d) to head (bcee43c).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant