Skip to content

Commit 334fc98

Browse files
authored
pce-mkcd: Skip PHDR sections which do not contain any data (BSS) (#387)
1 parent 3d49282 commit 334fc98

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

utils/pce-mkcd/pce-mkcd.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ class ElfDiscEntry : public DiscEntry {
371371
uint32_t phdr = phdr_offset + (phdr_size * i);
372372
if (int_at(elf_data, phdr + ELF32_PHDR_TYPE) == PT_LOAD) {
373373
uint32_t filesz = int_at(elf_data, phdr + ELF32_PHDR_FILESZ);
374+
if (!filesz) {
375+
// Skip PHDR sections which do not contain any data.
376+
continue;
377+
}
374378
uint32_t memsz = int_at(elf_data, phdr + ELF32_PHDR_MEMSZ);
375379
uint32_t low = int_at(elf_data, phdr + ELF32_PHDR_PADDR);
376380
uint32_t high = low + memsz - 1;
@@ -436,6 +440,9 @@ class ElfDiscEntry : public DiscEntry {
436440
if (int_at(elf_data, phdr + ELF32_PHDR_TYPE) == PT_LOAD) {
437441
uint32_t offset = int_at(elf_data, phdr + ELF32_PHDR_OFFSET);
438442
uint32_t filesz = int_at(elf_data, phdr + ELF32_PHDR_FILESZ);
443+
if (!filesz) {
444+
continue;
445+
}
439446
uint32_t addr = int_at(elf_data, phdr + ELF32_PHDR_PADDR);
440447
uint32_t file_offset = addr_to_file_offset(addr);
441448
memcpy(&data[file_offset], &elf_data[offset], filesz);

0 commit comments

Comments
 (0)