libfdisk: fix OOM on GPT with huge partition entries array
Add sanity checks to gpt_read_entries() to prevent out-of-memory when
reading a crafted GPT header with an absurdly large npartition_entries
value. The entries array size is now limited by:
- GPT_NPARTITIONS_MAX hard cap (~4MiB)
- first_usable_lba, since entries must fit before the first usable sector
Also reorder validation in gpt_read_header() to perform all cheap
header-only checks (my_lba, LBA sanity) before attempting to allocate
and read the entries array.
Addresses: https://github.com/util-linux/util-linux/issues/4432 Signed-off-by: Karel Zak <kzak@redhat.com>