Skip to content

Commit 50b3a81

Browse files
zhangyi089jankara
authored andcommitted
ext2: correct max file size computing
We need to calculate the max file size accurately if the total blocks that can address by block tree exceed the upper_limit. But this check is not correct now, it only compute the total data blocks but missing metadata blocks are needed. So in the case of "data blocks < upper_limit && total blocks > upper_limit", we will get wrong result. Fortunately, this case could not happen in reality, but it's confused and better to correct the computing. bits data blocks metadatablocks upper_limit 10 16843020 66051 2147483647 11 134480396 263171 1073741823 12 1074791436 1050627 536870911 (*) 13 8594130956 4198403 268435455 (*) 14 68736258060 16785411 134217727 (*) 15 549822930956 67125251 67108863 (*) 16 4398314962956 268468227 33554431 (*) [*] Need to calculate in depth. Fixes: 1c2d142 ("ext2: Fix underflow in ext2_max_size()") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Zhang Yi <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 48b0e01 commit 50b3a81

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/ext2/super.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,12 @@ static loff_t ext2_max_size(int bits)
753753
res += 1LL << (bits-2);
754754
res += 1LL << (2*(bits-2));
755755
res += 1LL << (3*(bits-2));
756+
/* Compute how many metadata blocks are needed */
757+
meta_blocks = 1;
758+
meta_blocks += 1 + ppb;
759+
meta_blocks += 1 + ppb + ppb * ppb;
756760
/* Does block tree limit file size? */
757-
if (res < upper_limit)
761+
if (res + meta_blocks <= upper_limit)
758762
goto check_lfs;
759763

760764
res = upper_limit;

0 commit comments

Comments
 (0)