Fixed offset calculation overflowing on large SD cards

This commit is contained in:
HelloWorldTeraByte
2026-03-04 09:33:37 +01:00
committed by Robin Krahl
parent 76c038e865
commit f31f4dc40d
2 changed files with 8 additions and 5 deletions
+3 -1
View File
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
-
### Fixed
- Fixed offset calculation overflow in `lfs_config_read` and `lfs_config_prog` if the offset is larger than `u32::MAX`.
## [v0.6.1](https://github.com/trussed-dev/littlefs2/releases/tag/0.6.1) - 2025-03-04
+5 -4
View File
@@ -536,8 +536,9 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
// println!("in lfs_config_read for {} bytes", size);
let storage = unsafe { &mut *((*c).context as *mut Storage) };
debug_assert!(!c.is_null());
let block_size = unsafe { c.read().block_size };
let off = (block * block_size + off) as usize;
// let block_size = unsafe { c.read().block_size };
let block_size = Storage::BLOCK_SIZE;
let off = block as usize * block_size + off as usize;
let buf: &mut [u8] = unsafe { slice::from_raw_parts_mut(buffer as *mut u8, size as usize) };
error_code_from(storage.read(off, buf))
@@ -556,8 +557,8 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
let storage = unsafe { &mut *((*c).context as *mut Storage) };
debug_assert!(!c.is_null());
// let block_size = unsafe { c.read().block_size };
let block_size = Storage::BLOCK_SIZE as u32;
let off = (block * block_size + off) as usize;
let block_size = Storage::BLOCK_SIZE;
let off = block as usize * block_size + off as usize;
let buf: &[u8] = unsafe { slice::from_raw_parts(buffer as *const u8, size as usize) };
error_code_from(storage.write(off, buf))