[gparted] Fix off by one sector error in GParted internal block copy (#742920)



commit 8a952cd4a9fea6d395c05f46d075aaf368011653
Author: Phillip Susi <psusi ubuntu com>
Date:   Wed Jan 14 16:47:10 2015 +0000

    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 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/Copy_Blocks.cc b/src/Copy_Blocks.cc
index d040951..392398a 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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]