From f7749b31de8611caa04c1fe1f281fc37a9e758b5 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 24 Nov 2020 01:37:54 -0800 Subject: [PATCH] Core: Fix loading ELF files that have unexpected empty program headers --- CHANGES | 1 + src/core/core.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 9f708cbe1..a989b93fb 100644 --- a/CHANGES +++ b/CHANGES @@ -56,6 +56,7 @@ Other fixes: - CMake: Link with correct OpenGL library (fixes mgba.io/i/1872) - Core: Ensure ELF regions can be written before trying - Core: Fix threading improperly setting paused state while interrupted + - Core: Fix loading ELF files that have unexpected empty program headers - Debugger: Don't skip undefined instructions when debugger attached - Debugger: Close trace log when done tracing - Debugger: Fix change watchpoints (fixes mgba.io/i/1947) diff --git a/src/core/core.c b/src/core/core.c index 4df6636a0..5afdc8667 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -382,6 +382,9 @@ bool mCoreLoadELF(struct mCore* core, struct ELF* elf) { for (i = 0; i < ELFProgramHeadersSize(&ph); ++i) { size_t bsize, esize; Elf32_Phdr* phdr = ELFProgramHeadersGetPointer(&ph, i); + if (!phdr->p_filesz) { + continue; + } void* block = mCoreGetMemoryBlockMasked(core, phdr->p_paddr, &bsize, mCORE_MEMORY_WRITE | mCORE_MEMORY_WORM); char* bytes = ELFBytes(elf, &esize); if (block && bsize >= phdr->p_filesz && esize > phdr->p_offset && esize >= phdr->p_filesz + phdr->p_offset) {