sz = (ssize_t) le32_to_cpu(header->npartition_entries) *
le32_to_cpu(header->sizeof_partition_entry);
+ if (sz == 0 || sz >= UINT32_MAX ||
+ le32_to_cpu(header->sizeof_partition_entry) != sizeof(struct gpt_entry)) {
+ DBG(LABEL, ul_debug("GPT entreis array size check failed"));
+ return NULL;
+ }
+
ret = calloc(1, sz);
if (!ret)
return NULL;
/* calculate the size (bytes) of the entries array */
new_size = entries * le32_to_cpu(gpt->pheader->sizeof_partition_entry);
+ if (new_size >= UINT32_MAX) {
+ fdisk_warnx(cxt, _("The number of the partition has be smaller than %zu."),
+ UINT32_MAX / le32_to_cpu(gpt->pheader->sizeof_partition_entry));
+ return -EINVAL;
+ }
+
old_size = old * le32_to_cpu(gpt->pheader->sizeof_partition_entry);
/* calculate new range of usable LBAs */