OSDN Git Service

avoid failed assertion when creating a GPT partition table...
authorJim Meyering <meyering@redhat.com>
Mon, 16 Feb 2009 18:02:58 +0000 (19:02 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 18 Feb 2009 19:25:27 +0000 (20:25 +0100)
on top of an old one for a larger device

* libparted/labels/gpt.c (gpt_read): Don't assert that the location
of the alternate LBA is within the current device.  It will be
beyond its end when the device it was created for was larger.
Instead, just return, treating this like any other non-match.

Here's the reproducer:

  dev=file
  dd     of=$dev if=/dev/null seek=4001
  parted -s $dev mklabel gpt
  dd     of=$dev if=/dev/null seek=4000
  parted -s $dev mklabel gpt

libparted/labels/gpt.c

index eea562d..ae74123 100644 (file)
@@ -4,7 +4,7 @@
     original version by Matt Domsch <Matt_Domsch@dell.com>
     Disclaimed into the Public Domain
 
-    Portions Copyright (C) 2001-2003, 2005-2008 Free Software Foundation, Inc.
+    Portions Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
 
     EFI GUID Partition Table handling
     Per Intel EFI Specification v1.02
@@ -824,8 +824,13 @@ gpt_read (PedDisk * disk)
                goto error;
 
        if (_read_header (disk->dev, &gpt, 1)) {
-               PED_ASSERT ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
-                               <= disk->dev->length - 1, goto error_free_gpt);
+               /* There used to be a GPT partition table here, with an
+                  alternate LBA that extended beyond the current
+                  end-of-device.  Treat it as a non-match.   */
+               if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
+                    > disk->dev->length - 1)
+                       goto error_free_gpt;
+
                if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
                                < disk->dev->length - 1) {
                        char* zeros = ped_malloc (pth_get_size (disk->dev));