Blame SOURCES/ntfsclone-full-clusters-bz1601146.patch

0f6478
--- ntfsprogs/ntfsclone.c	2018-05-16 18:46:47.114964000 +0200
0f6478
+++ ntfsprogs/ntfsclone.c	2018-07-16 14:03:20.273809100 +0200
0f6478
@@ -776,6 +776,10 @@ 
0f6478
 
0f6478
 		/* possible partial cluster holding the backup boot sector */
0f6478
 	backup_bootsector = (lcn + 1)*csize >= full_device_size;
0f6478
+	buff = (char*)ntfs_malloc(csize);
0f6478
+	if (!buff)
0f6478
+		err_exit("Not enough memory");
0f6478
+
0f6478
 	if (backup_bootsector) {
0f6478
 		csize = full_device_size - lcn*csize;
0f6478
 		if (csize < 0) {
0f6478
@@ -783,10 +787,6 @@ 
0f6478
 		}
0f6478
 	}
0f6478
 
0f6478
-	buff = (char*)ntfs_malloc(csize);
0f6478
-	if (!buff)
0f6478
-		err_exit("Not enough memory");
0f6478
-
0f6478
 // need reading when not about to write ?
0f6478
 	if (read_all(fd, buff, csize) == -1) {
0f6478
 
0f6478
@@ -1507,6 +1507,7 @@ 
0f6478
 	s64 mft_no;
0f6478
 	u32 mft_record_size;
0f6478
 	u32 csize;
0f6478
+	u32 buff_size;
0f6478
 	u32 bytes_per_sector;
0f6478
 	u32 records_per_set;
0f6478
 	u32 clusters_per_set;
0f6478
@@ -1524,15 +1525,18 @@ 
0f6478
 		/*
0f6478
 		 * Depending on the sizes, there may be several records
0f6478
 		 * per cluster, or several clusters per record.
0f6478
+		 * Anyway, full clusters are needed for rescuing bad ones.
0f6478
 		 */
0f6478
 	if (csize >= mft_record_size) {
0f6478
 		records_per_set = csize/mft_record_size;
0f6478
 		clusters_per_set = 1;
0f6478
+		buff_size = csize;
0f6478
 	} else {
0f6478
 		clusters_per_set = mft_record_size/csize;
0f6478
 		records_per_set = 1;
0f6478
+		buff_size = mft_record_size;
0f6478
 	}
0f6478
-	buff = (char*)ntfs_malloc(mft_record_size);
0f6478
+	buff = (char*)ntfs_malloc(buff_size);
0f6478
 	if (!buff)
0f6478
 		err_exit("Not enough memory");
0f6478
 
0f6478
@@ -1585,6 +1589,7 @@ 
0f6478
 	void *fd;
0f6478
 	u32 indx_record_size;
0f6478
 	u32 csize;
0f6478
+	u32 buff_size;
0f6478
 	u32 bytes_per_sector;
0f6478
 	u32 records_per_set;
0f6478
 	u32 clusters_per_set;
0f6478
@@ -1601,16 +1606,19 @@ 
0f6478
 		/*
0f6478
 		 * Depending on the sizes, there may be several records
0f6478
 		 * per cluster, or several clusters per record.
0f6478
+		 * Anyway, full clusters are needed for rescuing bad ones.
0f6478
 		 */
0f6478
 	indx_record_size = image->ni->vol->indx_record_size;
0f6478
 	if (csize >= indx_record_size) {
0f6478
 		records_per_set = csize/indx_record_size;
0f6478
 		clusters_per_set = 1;
0f6478
+		buff_size = csize;
0f6478
 	} else {
0f6478
 		clusters_per_set = indx_record_size/csize;
0f6478
 		records_per_set = 1;
0f6478
+		buff_size = indx_record_size;
0f6478
 	}
0f6478
-	buff = (char*)ntfs_malloc(indx_record_size);
0f6478
+	buff = (char*)ntfs_malloc(buff_size);
0f6478
 	if (!buff)
0f6478
 		err_exit("Not enough memory");
0f6478