From 8a952cd4a9fea6d395c05f46d075aaf368011653 Mon Sep 17 00:00:00 2001 From: Phillip Susi Date: Wed, 14 Jan 2015 16:47:10 +0000 Subject: [PATCH] Fix off by one sector error in GParted internal block copy (#742920) GParted's internal block copy has an off by one sector bug when the source is before the destination; and the copy is performed backwards from high block to low block. It is as though the source and destination partitions were both one sector earlier on the disk. In ASCII art it it looks like this: Initial layout: x<--SRC--><--DST--> Actually wrote: x<--SRC-- Should have written: <--SRC--> Affects moving partitions too. This bug has existed since commit: bd9e16f22fe3dfae73064369aadeda5de10b61be Thread the internal copy algorithm (#685740) Effectively the last sector of the partition is missed and one sector before the start of the partition is corrupted. Most of the time file systems don't get around to using the very last sector so didn't notice. Bug 742920 - GParted internal copy is overstepping partition boundaries --- src/Copy_Blocks.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Copy_Blocks.cc b/src/Copy_Blocks.cc index d0409519..392398a2 100644 --- a/src/Copy_Blocks.cc +++ b/src/Copy_Blocks.cc @@ -105,9 +105,9 @@ void copy_blocks::copy_thread() { blocksize -= 2*blocksize; done -= 2*done; - offset_src += ( (length / src_sector_size) - 1 ); + offset_src += length / src_sector_size; /* Handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required. */ - offset_dst += ( ((length + (dst_sector_size - 1)) / dst_sector_size) - 1 ); + offset_dst += (length + (dst_sector_size - 1)) / dst_sector_size; } success = true; } else success = false;