From: Jim Meyering <meyer...@redhat.com> * libparted/labels/gpt.c (_generate_header): Correct size of partition array entries to round up to nearest multiple of sector size, so that we set gpt->PartitionEntryLBA correctly also when the number of partition entries is not a multiple of sector_size / 128. Problem diagnosed by Robert Herndon in http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10173. --- NEWS | 5 +++++ libparted/labels/gpt.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS index b043ba1..c6e22f0 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,11 @@ GNU parted NEWS -*- outline -*- libparted: gpt_disk_duplicate now copies the flags over to the new disk object. Previously the flags would be undefined. + libparted can now read partition tables with a number of partition + array entries that is different from the default of 128. Before, + it would fail to recognize them and could even read beyond the end + of a heap-allocated buffer. + libparted: no longer aborts (failed assertion) due to a nilfs2_probe bug [bug introduced in parted-2.4 with the addition of nilfs2 support] diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c index e239a2d..454a177 100644 --- a/libparted/labels/gpt.c +++ b/libparted/labels/gpt.c @@ -1137,13 +1137,15 @@ _generate_header (const PedDisk *disk, int alternate, uint32_t ptes_crc, if (alternate) { - PedSector ptes_size = gpt_disk_data->entry_count - * sizeof (GuidPartitionEntry_t) / disk->dev->sector_size; + size_t ss = disk->dev->sector_size; + PedSector ptes_bytes = (gpt_disk_data->entry_count + * sizeof (GuidPartitionEntry_t)); + PedSector ptes_sectors = (ptes_bytes + ss - 1) / ss; gpt->MyLBA = PED_CPU_TO_LE64 (disk->dev->length - 1); gpt->AlternateLBA = PED_CPU_TO_LE64 (1); gpt->PartitionEntryLBA - = PED_CPU_TO_LE64 (disk->dev->length - 1 - ptes_size); + = PED_CPU_TO_LE64 (disk->dev->length - 1 - ptes_sectors); } else { -- 1.7.8.rc0.32.g87bf9 _______________________________________________ bug-parted mailing list bug-parted@gnu.org https://lists.gnu.org/mailman/listinfo/bug-parted