parted/parted-1.9.0-gpt-big-endian.patch

61 lines
2.3 KiB
Diff
Raw Normal View History

From d6e9b3bbda5eb565b6031b5620e38cba871c6748 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Tue, 6 Oct 2009 20:10:00 +0200
Subject: [PATCH parted 1/3] 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.
---
NEWS | 3 +++
libparted/labels/gpt.c | 12 +++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
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;
--
1.6.5.rc2