Re: [PATCH v2] fat: calculate data area start without overflow
From: OGAWA Hirofumi
Date: Wed Sep 02 2026 - 12:33:11 EST
hengyul@xxxxxxxxxx writes:
> - sbi->data_start = sbi->dir_start + rootdir_sectors;
> + if (check_mul_overflow(sbi->fats, sbi->fat_length,
> + &dir_start) ||
Looks like unreadable "\n".
if (check_mul_overflow(sbi->fats, sbi->fat_length, &dir_start) ||
> + check_add_overflow(sbi->fat_start, dir_start, &dir_start) ||
> + check_add_overflow(dir_start, rootdir_sectors, &data_start))
> + goto out_invalid;
Maybe, better to add the error detail?
check_add_overflow(dir_start, rootdir_sectors, &data_start)) {
if (!silent)
fat_msg(sb, KERN_ERR,
"overflow of root dir or data layout");
goto out_invalid;
}
Thanks.
> total_sectors = bpb.fat_sectors;
> if (total_sectors == 0)
> total_sectors = bpb.fat_total_sect;
>
> - if (total_sectors < sbi->data_start) {
> + if (total_sectors < data_start) {
> if (!silent)
> fat_msg(sb, KERN_ERR,
> - "data area starts beyond volume (%lu > %u)",
> - sbi->data_start, total_sectors);
> + "data area starts beyond volume (%u > %u)",
> + data_start, total_sectors);
> goto out_invalid;
> }
>
> - total_clusters = (total_sectors - sbi->data_start) / sbi->sec_per_clus;
> + sbi->dir_start = dir_start;
> + sbi->data_start = data_start;
> + total_clusters = (total_sectors - data_start) / sbi->sec_per_clus;
>
> if (!is_fat32(sbi))
> sbi->fat_bits = (total_clusters > MAX_FAT12) ? 16 : 12;
>
--
OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx>