Skip to content

Commit 78f87d5

Browse files
CsBoBoNicenashif
authored andcommitted
fs: ext2: Fix nbytes_to_read calculation in ext2_inode_read()
Fix incorrect nbytes_to_read calculation in ext2_inode_read() function. Previously nbytes_to_read was decremented by read value which caused incorrect calculation of bytes to read in subsequent iterations. Now nbytes_to_read is decremented by to_read value which represents the actual number of bytes read in current iteration. This fixes potential data corruption issues when reading files from ext2 filesystem. Signed-off-by: Chen Shu <[email protected]> (cherry picked from commit 5a5f05b)
1 parent c3e4c50 commit 78f87d5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/fs/ext2/ext2_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ ssize_t ext2_inode_read(struct ext2_inode *inode, void *buf, uint32_t offset, si
630630
memcpy((uint8_t *)buf + read, inode_current_block_mem(inode) + block_off, to_read);
631631

632632
read += to_read;
633-
nbytes_to_read -= read;
633+
nbytes_to_read -= to_read;
634634
offset += to_read;
635635
}
636636

0 commit comments

Comments
 (0)