Skip to content

fix(runtime): replace unchecked u64 offset arithmetic with checked_add in iouring.rs#3291

Open
vikions wants to merge 3 commits intocommonwarexyz:mainfrom
vikions:fix/iouring-offset-overflow
Open

fix(runtime): replace unchecked u64 offset arithmetic with checked_add in iouring.rs#3291
vikions wants to merge 3 commits intocommonwarexyz:mainfrom
vikions:fix/iouring-offset-overflow

Conversation

@vikions
Copy link

@vikions vikions commented Mar 3, 2026

Fixes #3288

Problem

Three locations in runtime/src/storage/iouring.rs used unchecked u64
addition when advancing the file offset during partial reads and writes.
If a caller supplies an offset near u64::MAX, the addition wraps around,
redirecting I/O to unintended earlier positions in the file.

Fix

Replaced all three unchecked additions with checked_add(...).ok_or(Error::OffsetOverflow)?:

  • write_single_at: offset update after partial write (line 324)
  • write_vectored_at: offset update after partial vectored write (line 408)
  • read_at_buf: offset update after partial read (line 455)

Tests

Added three regression tests covering near-u64::MAX offset scenarios for
each affected code path.

…d in iouring.rs

Fixes commonwarexyz#3288

Three locations in iouring.rs used unchecked u64 addition when
advancing the file offset across partial reads/writes. If the caller
supplies an offset near u64::MAX the addition can wrap, redirecting
I/O to unintended positions.

Replace all three with checked_add(...).ok_or(Error::OffsetOverflow)?
and add regression tests for each code path.
Test should verify no spurious OffsetOverflow, not that the write
succeeds — OS may return EINVAL at u64::MAX offset legitimately.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

u64::MAX - Header::SIZE_U64 did not trigger overflow because the
internal header add yields exactly u64::MAX, which io_uring treats
as current file position. Use +1 to reliably trigger OffsetOverflow.
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.

[medium] [runtime] integer overflow in runtime/src/storage/iouring.rs

1 participant