From 3f44974324de8c07ddc91655165f19725db5069d Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Sun, 5 Jan 2025 20:45:05 +0100 Subject: [PATCH] fix(elf,parser) check that segment's content is not empty --- src/ELF/Parser.tcc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ELF/Parser.tcc b/src/ELF/Parser.tcc index e4fe2c193..1e816f7e7 100644 --- a/src/ELF/Parser.tcc +++ b/src/ELF/Parser.tcc @@ -126,10 +126,13 @@ ok_error_t Parser::parse_binary() { int64_t rel_offset = seg_dyn->virtual_address() - load_seg.virtual_address(); assert(rel_offset >= 0); - span dynamic_content = load_seg.content().subspan(rel_offset); - SpanStream stream(dynamic_content); - stream.set_endian_swap(stream_->should_swap()); - parse_dynamic_entries(stream); + span seg_content = load_seg.content(); + if (!seg_content.empty()) { + span dynamic_content = seg_content.subspan(rel_offset); + SpanStream stream(dynamic_content); + stream.set_endian_swap(stream_->should_swap()); + parse_dynamic_entries(stream); + } } else /* No PT_LOAD segment wrapping up the PT_DYNAMIC table */ { const Elf_Off offset = seg_dyn->file_offset(); ScopedStream scoped(*stream_, offset);