Skip to content

Commit

Permalink
pce-mkcd: Skip PHDR sections which do not contain any data (BSS) (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka authored Jan 1, 2025
1 parent 3d49282 commit 334fc98
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils/pce-mkcd/pce-mkcd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ class ElfDiscEntry : public DiscEntry {
uint32_t phdr = phdr_offset + (phdr_size * i);
if (int_at(elf_data, phdr + ELF32_PHDR_TYPE) == PT_LOAD) {
uint32_t filesz = int_at(elf_data, phdr + ELF32_PHDR_FILESZ);
if (!filesz) {
// Skip PHDR sections which do not contain any data.
continue;
}
uint32_t memsz = int_at(elf_data, phdr + ELF32_PHDR_MEMSZ);
uint32_t low = int_at(elf_data, phdr + ELF32_PHDR_PADDR);
uint32_t high = low + memsz - 1;
Expand Down Expand Up @@ -436,6 +440,9 @@ class ElfDiscEntry : public DiscEntry {
if (int_at(elf_data, phdr + ELF32_PHDR_TYPE) == PT_LOAD) {
uint32_t offset = int_at(elf_data, phdr + ELF32_PHDR_OFFSET);
uint32_t filesz = int_at(elf_data, phdr + ELF32_PHDR_FILESZ);
if (!filesz) {
continue;
}
uint32_t addr = int_at(elf_data, phdr + ELF32_PHDR_PADDR);
uint32_t file_offset = addr_to_file_offset(addr);
memcpy(&data[file_offset], &elf_data[offset], filesz);
Expand Down

0 comments on commit 334fc98

Please sign in to comment.