diff --git a/core/relinker/relinker/src/parsing/ElfReader.cpp b/core/relinker/relinker/src/parsing/ElfReader.cpp index a214a56f8..81c62ebd8 100644 --- a/core/relinker/relinker/src/parsing/ElfReader.cpp +++ b/core/relinker/relinker/src/parsing/ElfReader.cpp @@ -130,6 +130,9 @@ std::vector ElfReader::ReadProgramHeaders() const { ph.MemorySize = _readU64At(offset + 0x28); ph.Alignment = _readU64At(offset + 0x30); + if (ph.Type == PT_LOAD && ph.FileSize > ph.MemorySize) + throw RelinkerException("PT_LOAD file size exceeds memory size", ph.Offset); + headers.push_back(ph); offset += header.ProgramHeaderEntrySize; } diff --git a/core/relinker/relinker/tests/test_linux_load_alignment.py b/core/relinker/relinker/tests/test_linux_load_alignment.py index f3b0c356b..51008e939 100644 --- a/core/relinker/relinker/tests/test_linux_load_alignment.py +++ b/core/relinker/relinker/tests/test_linux_load_alignment.py @@ -54,6 +54,16 @@ def main(): if alignment != 0x4000 or first[3] % alignment != 0 or first[7] != alignment: raise AssertionError(("first PT_LOAD is not aligned to the largest segment alignment", segments)) assert " |-- output.elf\n |-- libs/\n |-- *.prx (system libraries)\n |-- app0/" in result.stdout, result.stdout + + malformed = fixture() + struct.pack_into("