Skip to content

Commit 83b6db1

Browse files
author
HelloWorldTeraByte
committed
Fixed offset calculation overflowing on large SD cards
1 parent 4eec5f2 commit 83b6db1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/fs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,9 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
536536
// println!("in lfs_config_read for {} bytes", size);
537537
let storage = unsafe { &mut *((*c).context as *mut Storage) };
538538
debug_assert!(!c.is_null());
539-
let block_size = unsafe { c.read().block_size };
540-
let off = (block * block_size + off) as usize;
539+
// let block_size = unsafe { c.read().block_size };
540+
let block_size = Storage::BLOCK_SIZE;
541+
let off = block as usize * block_size + off as usize;
541542
let buf: &mut [u8] = unsafe { slice::from_raw_parts_mut(buffer as *mut u8, size as usize) };
542543

543544
error_code_from(storage.read(off, buf))
@@ -556,8 +557,8 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
556557
let storage = unsafe { &mut *((*c).context as *mut Storage) };
557558
debug_assert!(!c.is_null());
558559
// let block_size = unsafe { c.read().block_size };
559-
let block_size = Storage::BLOCK_SIZE as u32;
560-
let off = (block * block_size + off) as usize;
560+
let block_size = Storage::BLOCK_SIZE;
561+
let off = block as usize * block_size + off as usize;
561562
let buf: &[u8] = unsafe { slice::from_raw_parts(buffer as *const u8, size as usize) };
562563

563564
error_code_from(storage.write(off, buf))

0 commit comments

Comments
 (0)