Skip to content

Commit 8d0e455

Browse files
rizlikdanielinux
authored andcommitted
gpt.c: set part->end corrently including the last LBA of a partition
1 parent 72ac5a5 commit 8d0e455

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/gpt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ int gpt_parse_partition(const uint8_t *entry_data, uint32_t entry_size,
152152
if (pe->first > pe->last) {
153153
return -1;
154154
}
155+
/* LBA 0 is the protective MBR; no valid partition can end there */
156+
if (pe->last == 0) {
157+
return -1;
158+
}
155159

156160
/* Extract partition info (convert LBA to byte offsets) */
157161
part->start = pe->first * GPT_SECTOR_SIZE;
158-
part->end = (pe->last * GPT_SECTOR_SIZE) - 1;
162+
part->end = ((pe->last + 1) * GPT_SECTOR_SIZE) - 1;
159163
memcpy(part->name, pe->name, sizeof(part->name));
160164

161165
return 0;

0 commit comments

Comments
 (0)