Skip to content

Commit 44e2ca4

Browse files
committed
littlefs: Fix block addr overflow
deepikabhavnani did the hard work in tracking this issue down. Block addresses are not cast to the correct type until after multiplying to convert to byte addresses. This results in an overflow when the storage is larger than 4 GB.
1 parent b590051 commit 44e2ca4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

features/filesystem/littlefs/LittleFileSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ static int lfs_totype(int type)
8585
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
8686
lfs_off_t off, void *buffer, lfs_size_t size) {
8787
BlockDevice *bd = (BlockDevice *)c->context;
88-
return bd->read(buffer, block*c->block_size + off, size);
88+
return bd->read(buffer, (bd_addr_t)block*c->block_size + off, size);
8989
}
9090

9191
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
9292
lfs_off_t off, const void *buffer, lfs_size_t size) {
9393
BlockDevice *bd = (BlockDevice *)c->context;
94-
return bd->program(buffer, block*c->block_size + off, size);
94+
return bd->program(buffer, (bd_addr_t)block*c->block_size + off, size);
9595
}
9696

9797
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
9898
{
9999
BlockDevice *bd = (BlockDevice *)c->context;
100-
return bd->erase(block*c->block_size, c->block_size);
100+
return bd->erase((bd_addr_t)block*c->block_size, c->block_size);
101101
}
102102

103103
static int lfs_bd_sync(const struct lfs_config *c)

0 commit comments

Comments
 (0)