From 07b2450d1eda5ecaaeaac1940b606542f5a738d4 Mon Sep 17 00:00:00 2001 From: Yuezhang Mo Date: Wed, 11 Oct 2023 18:42:11 +0800 Subject: [PATCH] libblkid: exfat: fix fail to find volume label MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit f98b56326 set the maximum number of iterations to 10000. If the volume label is after the 10000th entry, the volume label will not be found. So this commit sets the maximum number of iterations to correct value 256×1024×1024/32. Fixes: f98b56326 ("libblkid: [exfat] Limit maximum number of iterations in find_label") Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- libblkid/src/superblocks/exfat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libblkid/src/superblocks/exfat.c b/libblkid/src/superblocks/exfat.c index 554868f4f8..06ad5c8c02 100644 --- a/libblkid/src/superblocks/exfat.c +++ b/libblkid/src/superblocks/exfat.c @@ -49,6 +49,8 @@ struct exfat_entry_label { #define EXFAT_ENTRY_EOD 0x00 #define EXFAT_ENTRY_LABEL 0x83 +#define EXFAT_MAX_DIR_SIZE (256 * 1024 * 1024) + static uint64_t block_to_offset(const struct exfat_super_block *sb, uint64_t block) { @@ -91,7 +93,7 @@ static struct exfat_entry_label *find_label(blkid_probe pr, uint32_t cluster = le32_to_cpu(sb->FirstClusterOfRootDirectory); uint64_t offset = cluster_to_offset(sb, cluster); uint8_t *entry; - const size_t max_iter = 10000; + const size_t max_iter = EXFAT_MAX_DIR_SIZE / EXFAT_ENTRY_SIZE; size_t i = 0; for (; i < max_iter; i++) { -- 2.47.3