elf2uf2: correctly parse ELF files where the program header is not directly following the file header
fixes #506
diff --git a/tools/elf2uf2/main.cpp b/tools/elf2uf2/main.cpp
index b66f082..2c0ddcd 100644
--- a/tools/elf2uf2/main.cpp
+++ b/tools/elf2uf2/main.cpp
@@ -143,6 +143,9 @@
}
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();
}