Skip to content

Commit 7916566

Browse files
committed
fix very large steps
1 parent 6f891df commit 7916566

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/addr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use crate::structures::paging::page_table::PageTableLevel;
1111
use crate::structures::paging::{PageOffset, PageTableIndex};
1212
use bit_field::BitField;
1313

14+
const ADDRESS_SPACE_SIZE: u64 = 0x1_0000_0000_0000;
15+
1416
/// A canonical 64-bit virtual memory address.
1517
///
1618
/// This is a wrapper type around an `u64`, so it is always 8 bytes, even when compiled
@@ -341,6 +343,10 @@ impl Step for VirtAddr {
341343

342344
fn forward_checked(start: Self, count: usize) -> Option<Self> {
343345
let offset = u64::try_from(count).ok()?;
346+
if offset > ADDRESS_SPACE_SIZE {
347+
return None;
348+
}
349+
344350
let mut addr = start.0.checked_add(offset)?;
345351

346352
// Jump the gap by sign extending the 47th bit.
@@ -353,6 +359,10 @@ impl Step for VirtAddr {
353359

354360
fn backward_checked(start: Self, count: usize) -> Option<Self> {
355361
let offset = u64::try_from(count).ok()?;
362+
if offset > ADDRESS_SPACE_SIZE {
363+
return None;
364+
}
365+
356366
let mut addr = start.0.checked_sub(offset)?;
357367

358368
// Jump the gap by sign extending the 47th bit.

0 commit comments

Comments
 (0)