From ccc0ba56492ef8c4b7b0efcd4f65d1e7a3124683 Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Wed, 14 Jul 2021 21:59:09 +0100 Subject: [PATCH] elf2uf2: correctly parse ELF files where the program header is not directly following the file header fixes #506 --- tools/elf2uf2/main.cpp | 3 +++ 1 file changed, 3 insertions(+) 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 @@ int read_and_check_elf32_ph_entries(FILE *in, const elf32_header &eh, const addr } if (eh.ph_num) { std::vector 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(); }