From 75b0e5cce50b1cf126ea83f1de78fe1a03c5d425 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 25 May 2019 19:19:43 +0200 Subject: [PATCH] Ext2FS: Block #0 can terminate an inode block list early. We were already handling this for the indirect blocks, but the direct ones would happily consider #0 to be a valid block list entry. --- Kernel/FileSystem/Ext2FileSystem.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 838ac88793..13e3b93fd1 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -269,6 +269,11 @@ Vector Ext2FS::block_list_for_inode(const ext2_inode& e2inod // NOTE: i_blocks is number of 512-byte blocks, not number of fs-blocks. unsigned block_count = e2inode.i_blocks / (block_size() / 512); + +#ifdef EXT2_DEBUG + dbgprintf("Ext2FS::block_list_for_inode(): i_size=%u, i_blocks=%u, block_count=%u\n", e2inode.i_size, block_count); +#endif + unsigned blocks_remaining = block_count; Vector list; if (include_block_list_blocks) { @@ -280,7 +285,10 @@ Vector Ext2FS::block_list_for_inode(const ext2_inode& e2inod unsigned direct_count = min(block_count, (unsigned)EXT2_NDIR_BLOCKS); for (unsigned i = 0; i < direct_count; ++i) { - list.unchecked_append(e2inode.i_block[i]); + auto block_index = e2inode.i_block[i]; + if (!block_index) + return list; + list.unchecked_append(block_index); --blocks_remaining; }