From 732f5f0f87207ad81a5d3c4a6d6fbb32b4d618e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 25 Jun 2022 09:25:42 +0200 Subject: [PATCH] ext2: accept block count until the disk size plus one my understanding is that it's possible that the last block (for instance of size 4KB) is too large for the last few partition sectors, if the partition size isn't a multiple of the block size. Change-Id: I88c709d6e449aa52358fd9343c9f68f7ac1c01fe Reviewed-on: https://review.haiku-os.org/c/haiku/+/5399 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- src/add-ons/kernel/file_systems/ext2/Volume.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/file_systems/ext2/Volume.cpp b/src/add-ons/kernel/file_systems/ext2/Volume.cpp index 7727c1f901..dff0520458 100644 --- a/src/add-ons/kernel/file_systems/ext2/Volume.cpp +++ b/src/add-ons/kernel/file_systems/ext2/Volume.cpp @@ -233,8 +233,10 @@ Volume::Mount(const char* deviceName, uint32 flags) status = opener.GetSize(&diskSize); if (status != B_OK) return status; - if (diskSize < ((off_t)NumBlocks() << BlockShift())) + if ((diskSize + fBlockSize) <= ((off_t)NumBlocks() << BlockShift())) { + FATAL("diskSize is too small for the number of blocks!\n"); return B_BAD_VALUE; + } fBlockCache = opener.InitCache(NumBlocks(), fBlockSize); if (fBlockCache == NULL)