From: Jim Meyering Date: Tue, 6 Oct 2009 18:10:00 +0000 (+0200) Subject: gpt: don't malfunction on big-endian systems X-Git-Tag: android-x86-4.4-r1~611 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d6e9b3bb;p=android-x86%2Fexternal-parted.git gpt: don't malfunction on big-endian systems Numerous GPT tests would fail when run on e.g., big-endian PPC. * libparted/labels/gpt.c (gpt_read): Now that we use the SizeOfPartitionEntry member, be sure to convert from GPT's little-endian on-disk format to to CPU endianness. This bug was introduced via commit 14cce9b2, 2009-06-10, "gpt: fix gpt_read to read all of the partition entries correctly". * libparted/labels/gpt.c (_header_is_valid): Also convert it here. Add a test to ensure that the partition entry size is no larger than the slightly arbitrary UINT32_MAX/16. * NEWS (Bug fixes): Mention it. --- diff --git a/NEWS b/NEWS index 04741a2..d4147ad 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ GNU parted NEWS -*- outline -*- ** Bug fixes + big-endian systems can once again read GPT partition tables + [bug introduced in parted-1.9.0] + ped_partition_is_busy no longer calls libparted's exception handler, since doing so caused trouble with anaconda/pyparted when operating on dmraid devices. diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c index cc9bcdc..b4549ef 100644 --- a/libparted/labels/gpt.c +++ b/libparted/labels/gpt.c @@ -608,8 +608,10 @@ _header_is_valid (const PedDevice* dev, GuidPartitionTableHeader_t* gpt) * the SizeOfPartitionEntry must be a multiple of 8 and * no smaller than the size of the PartitionEntry structure. */ - uint32_t sope = gpt->SizeOfPartitionEntry; - if (sope % 8 != 0 || sope < sizeof(GuidPartitionEntry_t) ) + uint32_t sope = PED_LE32_TO_CPU (gpt->SizeOfPartitionEntry); + if (sope % 8 != 0 + || sope < sizeof (GuidPartitionEntry_t) + || (UINT32_MAX >> 4) < sope) return 0; origcrc = gpt->HeaderCRC32; @@ -911,7 +913,8 @@ gpt_read (PedDisk * disk) if (!_parse_header (disk, gpt, &write_back)) goto error_free_gpt; - ptes_sectors = ped_div_round_up (gpt->SizeOfPartitionEntry + uint32_t p_ent_size = PED_LE32_TO_CPU (gpt->SizeOfPartitionEntry); + ptes_sectors = ped_div_round_up (p_ent_size * gpt_disk_data->entry_count, disk->dev->sector_size); @@ -926,8 +929,7 @@ gpt_read (PedDisk * disk) for (i = 0; i < gpt_disk_data->entry_count; i++) { GuidPartitionEntry_t* pte - = (GuidPartitionEntry_t*) ((char *)ptes + i - * gpt->SizeOfPartitionEntry); + = (GuidPartitionEntry_t*) ((char *)ptes + i * p_ent_size); PedPartition* part; PedConstraint* constraint_exact;