Skip to content

Commit 57df877

Browse files
committed
rust: add proper overflow check
1 parent f6cf2a8 commit 57df877

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

bindings/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl Instance {
299299
let offset = offset as usize;
300300
let memory_size = self.memory_size();
301301
// Empty slices are allowed, but ensure both starting and ending offsets are valid.
302-
if memory_size == 0 || offset > memory_size || (offset + size) > memory_size {
302+
if memory_size == 0 || offset.checked_add(size).is_none() || (offset + size) > memory_size {
303303
return Err(());
304304
}
305305
debug_assert!(memory_size != 0);

0 commit comments

Comments
 (0)