Skip to content

Commit

Permalink
Check overflow for memory read
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Jan 13, 2025
1 parent bf4e465 commit 9826ad5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rvgo/fast/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (r *memReader) Read(dest []byte) (n int, err error) {
return 0, io.EOF
}

if r.addr > 1<<64-1-r.count {
// If adding r.count to r.addr would exceed the maximum uint64 value,
// we consider that an overflow condition and stop.
return 0, io.EOF
}

// Keep iterating over memory until we have all our data.
// It may wrap around the address range, and may not be aligned
endAddr := r.addr + r.count
Expand Down

0 comments on commit 9826ad5

Please sign in to comment.