File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -373,7 +373,9 @@ class elf_object
373373 // Try to find it in phdr data instead of allocating new section
374374 p_index++;
375375
376- if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size <= hdr.p_offset + hdr.p_filesz )
376+ if (hdr.p_offset <= shdr.sh_offset &&
377+ shdr.sh_size <= hdr.p_filesz &&
378+ shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size )
377379 {
378380 const auto & prog = ::at32 (progs, p_index);
379381 shdrs.back ().bin_view = {prog.bin .data () + shdr.sh_offset - hdr.p_offset , shdr.sh_size };
@@ -469,7 +471,9 @@ class elf_object
469471 p_index++;
470472
471473 // Rely on previous sh_offset value!
472- if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size - 1 <= hdr.p_offset + hdr.p_filesz - 1 )
474+ if (hdr.p_offset <= shdr.sh_offset &&
475+ shdr.sh_size <= hdr.p_filesz &&
476+ shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size )
473477 {
474478 out.sh_offset = ::narrow<sz_t >(data_base + static_cast <usz>(shdr.sh_offset - hdr.p_offset ));
475479 result = true ;
You can’t perform that action at this time.
0 commit comments