From ae6bad499a6cece3419e75a6560668032910e0f8 Mon Sep 17 00:00:00 2001 From: Yura Pakhuchiy Date: Fri, 19 Oct 2007 21:16:24 +0300 Subject: [PATCH] Avoid endless loop on damaged volumes --- libntfs/bootsect.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libntfs/bootsect.c b/libntfs/bootsect.c index 4278ac1f..a346904c 100644 --- a/libntfs/bootsect.c +++ b/libntfs/bootsect.c @@ -196,13 +196,18 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) sle64_to_cpu(bs->number_of_sectors)); ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster); if (sectors_per_cluster & (sectors_per_cluster - 1)) { - ntfs_log_debug("Error: %s is not a valid NTFS partition! " + ntfs_log_error("Error: %s is not a valid NTFS partition! " "sectors_per_cluster is not a power of 2.\n", vol->dev->d_name); return -1; } vol->nr_clusters = sle64_to_cpu(bs->number_of_sectors) >> (ffs(sectors_per_cluster) - 1); + if (!vol->nr_clusters) { + ntfs_log_error("Error: %s is not a valid NTFS partition! " + "nr_clusters is 0.\n", vol->dev->d_name); + return -1; + } vol->mft_lcn = sle64_to_cpu(bs->mft_lcn); vol->mftmirr_lcn = sle64_to_cpu(bs->mftmirr_lcn); @@ -210,15 +215,15 @@ int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) ntfs_log_debug("MFTMirr LCN = 0x%llx\n", vol->mftmirr_lcn); if (vol->mft_lcn > vol->nr_clusters || vol->mftmirr_lcn > vol->nr_clusters) { - ntfs_log_debug("Error: %s is not a valid NTFS partition!\n", + ntfs_log_error("Error: %s is not a valid NTFS partition!\n", vol->dev->d_name); - ntfs_log_debug("($Mft LCN or $MftMirr LCN is greater than the " + ntfs_log_error("($Mft LCN or $MftMirr LCN is greater than the " "number of clusters!)\n"); return -1; } vol->cluster_size = sectors_per_cluster * vol->sector_size; if (vol->cluster_size & (vol->cluster_size - 1)) { - ntfs_log_debug("Error: %s is not a valid NTFS partition! " + ntfs_log_error("Error: %s is not a valid NTFS partition! " "cluster_size is not a power of 2.\n", vol->dev->d_name); return -1;