[PATCH 2/2] avoid failed assertion when creating a GPT partition table...

Jim Meyering meyering at redhat.com
Mon Feb 16 18:02:58 UTC 2009


on top of an old one for a larger device

Here's the reproducer:

dev=file
dd if=/dev/null of=$dev bs=1 seek=30M
./parted -s $dev mklabel gpt
dd if=$dev of=prim_gpt_before bs=512 count=1 skip=1 2>/dev/null
./parted -m -s $dev p
truncate -s +10M $dev
./parted -m -s $dev p
dd if=/dev/null of=$dev bs=1 seek=30M
./parted -s $dev mklabel gpt
---
 libparted/labels/gpt.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 13d2e88..62beead 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -4,7 +4,7 @@
     original version by Matt Domsch <Matt_Domsch at 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));
--
1.6.2.rc0.264.g60787



More information about the parted-devel mailing list