From c3bc227168232b4d738f4e6f2a98e780c2e4c08b Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Sat, 21 Mar 2026 21:49:33 -0500 Subject: [PATCH] Fix padding handling in note parsing resulting in "region out-of-bounds" The actual note content might not be well-aligned, so the linker might pad the section. In this case, `remaining_` will _not_ be empty, but it might not be big enough to read a full `Elf_Note` header, resulting in an out-of-bounds access. This fixes failures on some binaries resulting in > bloaty: region out-of-bounds In particular, this happens with Qt binaries which embed `.note.qt.metadata` section with pretty much arbitrary internal length. --- src/elf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elf.cc b/src/elf.cc index ac0f6103..979900fc 100644 --- a/src/elf.cc +++ b/src/elf.cc @@ -427,7 +427,7 @@ void ElfFile::Section::ReadRelocationWithAddend(Elf64_Word index, } void ElfFile::NoteIter::Next() { - if (remaining_.empty()) { + if (remaining_.size() < sizeof(Elf_Note)) { done_ = true; return; }