diff --git a/partition/gpt/partition.go b/partition/gpt/partition.go index 86a4cdc8..a454ec23 100644 --- a/partition/gpt/partition.go +++ b/partition/gpt/partition.go @@ -1,6 +1,7 @@ package gpt import ( + "bytes" "encoding/binary" "fmt" "io" @@ -15,6 +16,8 @@ import ( // PartitionEntrySize fixed size of a GPT partition entry const PartitionEntrySize = 128 +var zeroUUIDBytes = make([]byte, 16) + // Partition represents the structure of a single partition on the disk type Partition struct { Start uint64 // start sector for the partition @@ -90,6 +93,9 @@ func partitionFromBytes(b []byte, logicalSectorSize, physicalSectorSize int) (*P return nil, fmt.Errorf("data for partition was %d bytes instead of expected %d", len(b), PartitionEntrySize) } // is it all zeroes? + if bytes.Equal(b[0:16], zeroUUIDBytes) { + return nil, nil + } typeGUID, err := uuid.FromBytes(bytesToUUIDBytes(b[0:16])) if err != nil { return nil, fmt.Errorf("unable to read partition type GUID: %v", err) diff --git a/partition/gpt/table.go b/partition/gpt/table.go index b16b2bfd..0da5dde1 100644 --- a/partition/gpt/table.go +++ b/partition/gpt/table.go @@ -337,6 +337,9 @@ func readPartitionArrayBytes(b []byte, entrySize, logicalSectorSize, physicalSec if err != nil { return nil, fmt.Errorf("error reading partition entry %d: %v", i, err) } + if p == nil { + continue + } // augment partition information p.Size = (p.End - p.Start + 1) * uint64(logicalSectorSize) parts = append(parts, p)