elf2uf2: correctly parse ELF files where the program header is not directly following the file header

fixes #506
This commit is contained in:
Gabriel Wang 2021-07-14 21:59:09 +01:00 committed by GitHub
parent 5e05469373
commit ccc0ba5649
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,6 +143,9 @@ int read_and_check_elf32_ph_entries(FILE *in, const elf32_header &eh, const addr
}
if (eh.ph_num) {
std::vector<elf32_ph_entry> entries(eh.ph_num);
if (fseek(in, eh.ph_offset, SEEK_SET)) {
return fail_read_error();
}
if (eh.ph_num != fread(&entries[0], sizeof(struct elf32_ph_entry), eh.ph_num, in)) {
return fail_read_error();
}