-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a crash in CCP and zero-filling issues in CCP and LDC #524
Changes from all commits
f838ace
87d8329
d59ca31
97a8bae
7375d11
c7bb4e2
e2d4b40
e0ebc0e
5651929
46a4c42
4b425af
4c9ea0c
4323732
df03c07
6c5313e
694741f
0c3bb19
d1381c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,13 @@ impl MemoryRange { | |
Self(start..end) | ||
} | ||
|
||
/// Splits range at given relative offset. Panics if offset > range length. | ||
pub fn split_at_offset(self, at: usize) -> (Self, Self) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should return an optional return type here instead of using a panicking assert? Since this is a public api it may be hard to guarantee that it's used correctly in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems you use this function only in one place, so maybe it is better to move this code there instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API here mirrors |
||
let mid = self.0.start + at; | ||
assert!(mid <= self.0.end); | ||
(Self(self.0.start..mid), Self(mid..self.0.end)) | ||
} | ||
|
||
/// This function is safe because it is only used to shrink the range | ||
/// and worst case the range will be empty. | ||
pub fn shrink_end(&mut self, by: usize) { | ||
|
@@ -707,3 +714,23 @@ pub(crate) fn write_bytes<const COUNT: usize>( | |
memory[range.usizes()].copy_from_slice(&bytes); | ||
Ok(()) | ||
} | ||
|
||
/// Attempt copy from slice to memory, filling zero bytes when exceeding slice boundaries. | ||
/// Performs overflow and memory range checks, but no ownership checks. | ||
pub(crate) fn copy_from_slice_zero_fill_noownerchecks<A: ToAddr, B: ToAddr>( | ||
memory: &mut [u8; MEM_SIZE], | ||
src: &[u8], | ||
dst_addr: A, | ||
src_offset: usize, | ||
len: B, | ||
) -> Result<(), RuntimeError> { | ||
let range = MemoryRange::new(dst_addr, len)?; | ||
|
||
let src_end = src_offset.saturating_add(range.len()).min(src.len()); | ||
let data = src.get(src_offset..src_end).unwrap_or_default(); | ||
let (r_data, r_zero) = range.split_at_offset(data.len()); | ||
memory[r_data.usizes()].copy_from_slice(data); | ||
memory[r_zero.usizes()].fill(0); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to worry about padding here? Or is it the responsibility of the
CCP
user?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm it's not in the specs. I guess since this isn't meant to be executable code it's not so relevant here.