]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libfdisk: fix OOM on GPT with huge partition entries array
authorKarel Zak <kzak@redhat.com>
Mon, 22 Jun 2026 08:25:12 +0000 (10:25 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Jun 2026 08:25:12 +0000 (10:25 +0200)
commitc6a01958c4eb01833a2b2325562e8ff6921a67a0
tree85539b86916e9149139204f38e779e0ca12973ed
parentc86a60b6a7f9ed33c2826692df17c0f15da6d273
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>
libfdisk/src/gpt.c