fix(runtime): replace unchecked u64 offset arithmetic with checked_add in iouring.rs#3291
Open
vikions wants to merge 3 commits intocommonwarexyz:mainfrom
Open
fix(runtime): replace unchecked u64 offset arithmetic with checked_add in iouring.rs#3291vikions wants to merge 3 commits intocommonwarexyz:mainfrom
vikions wants to merge 3 commits intocommonwarexyz:mainfrom
Conversation
…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.
There was a problem hiding this comment.
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.
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.
Fixes #3288
Problem
Three locations in
runtime/src/storage/iouring.rsused uncheckedu64addition 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::MAXoffset scenarios foreach affected code path.