Skip to content

Conversation

roberto-bayardo
Copy link
Collaborator

@roberto-bayardo roberto-bayardo commented Aug 15, 2025

addresses #1349

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses overflow vulnerabilities in buffer offset calculations by replacing unchecked addition with checked arithmetic operations. The change prevents potential integer overflow scenarios when calculating buffer end offsets.

  • Replaces unchecked addition (+) with checked_add() and explicit overflow handling
  • Adds overflow detection to offset calculation in extract and merge methods
  • Maintains existing panic behavior while making overflow conditions explicit

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@commonwarexyz commonwarexyz deleted a comment from Copilot AI Aug 15, 2025
@commonwarexyz commonwarexyz deleted a comment from Copilot AI Aug 15, 2025
dnkolegov-ar
dnkolegov-ar previously approved these changes Aug 15, 2025
@dnkolegov-ar
Copy link
Collaborator

Will adapt the fuzz tests in denis/new-fuzz-tests after merging into main

/// caller is responsible for continuing to manage the data.
pub(super) fn merge(&mut self, data: &[u8], offset: u64) -> bool {
let end_offset = offset + data.len() as u64;
let end_offset = offset.checked_add(data.len() as u64).expect("overflow");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for both of these cases, can we add more detail into "what overflowed"?

I'd prefer something like "offset overflowed"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to end_offset overflowed

@roberto-bayardo roberto-bayardo merged commit d49fa19 into main Aug 16, 2025
37 checks passed
@roberto-bayardo roberto-bayardo deleted the checked-add branch August 16, 2025 15:01
Copy link

codecov bot commented Aug 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.69%. Comparing base (69c166a) to head (21a5e6b).
⚠️ Report is 1 commits behind head on main.

@@            Coverage Diff             @@
##             main    #1406      +/-   ##
==========================================
- Coverage   91.69%   91.69%   -0.01%     
==========================================
  Files         275      275              
  Lines       69192    69197       +5     
==========================================
+ Hits        63447    63451       +4     
- Misses       5745     5746       +1     
Files with missing lines Coverage Δ
runtime/src/utils/buffer/tip.rs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69c166a...21a5e6b. Read the comment docs.

🚀 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.

3 participants