Skip to content

Commit

Permalink
fs/ext2: Fix file size check
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed Oct 27, 2023
1 parent 47e3d56 commit 90c0a5e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Empty file removed cross_file.txt
Empty file.
4 changes: 3 additions & 1 deletion src/fs/ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ static usize ext4_inode_data_read_helper(Ext2Partition* self, Ext4ExtentHeader*
}

for (u16 j = real_skip; j < num_blocks; ++j) {
assert(ptr < offset(data, void*, max_read));

void* data_ptr = ext2_block_read(self, start_block + j);
if (max_read - read >= self->block_size) {
if (skip_bytes) {
Expand Down Expand Up @@ -252,7 +254,7 @@ static usize ext4_inode_data_read_helper(Ext2Partition* self, Ext4ExtentHeader*

int ext4_inode_data_read(Ext2Partition* self, InodeDesc* inode, usize off, void* data, usize size) {
assert(inode->i_flags & 0x80000);
if (off >= inode->i_size) {
if (off + size > inode->i_size) {
return ERR_INVALID_ARG;
}

Expand Down

0 comments on commit 90c0a5e

Please sign in to comment.