]> git.ipfire.org Git - thirdparty/elfutils.git/commit
elf_begin.c: Use relative offset in archive size check
authorAaron Merey <amerey@redhat.com>
Mon, 8 Sep 2025 02:17:28 +0000 (22:17 -0400)
committerAaron Merey <amerey@redhat.com>
Tue, 9 Sep 2025 13:37:21 +0000 (09:37 -0400)
commit180945cb0f7cc129494bde7908dc5709fff7662c
tree1d3dcb573b045fbc3dfcff32483d7d0a81910f3a
parent685e4ad915f0c594696d9fdae9ab4074d250392d
elf_begin.c: Use relative offset in archive size check

Before creating an elf descriptor for an archive member, dup_elf
verifies that the size of an archive is large enough to contain the
member.  This check uses the member's offset relative to the map_address
of the top-level archive containing the member.

This check can incorrectly fail when an archive contains another
archive as a member.  For members of the inner archive, their offset
relative to the outer archive might be significantly larger than
the max_size of the inner archive.  This appears as if the offset and
max_size values are inconsistent and the creation of the member's elf
descriptor is stopped unnecessarily.

Fix this by accounting for the inner archive's non-zero start_offset
when judging whether the member can fit within it.

Also perform this size check before creating a copy of the member's
Elf_Arhdr to prevent leaking the header's ar_name and ar_rawname if
the size check fails.

Signed-off-by: Aaron Merey <amerey@redhat.com>
libelf/elf_begin.c