From 0574007d288a6743b5448b5f630be95ec4abb0e7 Mon Sep 17 00:00:00 2001 From: Aizal Khan Date: Wed, 24 Jun 2026 18:23:16 +0530 Subject: [PATCH] Avoid out-of-bounds section_starts_ read on invalid reloc index An out-of-range reloc.* section index leaves reloc_section_ as BinarySection::Invalid; the details-mode OnRelocCount ignored the base error and let OnReloc index section_starts_ with the sentinel. Propagate the result so the section is rejected. --- src/binary-reader-objdump.cc | 2 +- test/binary/bad-relocs.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index b2ae365440..6c7039abb5 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -2161,7 +2161,7 @@ Result BinaryReaderObjdump::OnDylinkNeeded(std::string_view so_name) { } Result BinaryReaderObjdump::OnRelocCount(Index count, Index section_index) { - BinaryReaderObjdumpBase::OnRelocCount(count, section_index); + CHECK_RESULT(BinaryReaderObjdumpBase::OnRelocCount(count, section_index)); PrintDetails(" - relocations for section: %d (" PRIstringview ") [%d]\n", section_index, WABT_PRINTF_STRING_VIEW_ARG(GetSectionName(section_index)), diff --git a/test/binary/bad-relocs.txt b/test/binary/bad-relocs.txt index 6240ced061..2ca701a611 100644 --- a/test/binary/bad-relocs.txt +++ b/test/binary/bad-relocs.txt @@ -4,7 +4,10 @@ magic version section("reloc.BAD") { reloc_section[99] - reloc_count[0] + reloc_count[1] + reloc_type[0] ;; R_WASM_FUNCTION_INDEX_LEB + offset[0] + index[0] } (;; STDERR ;;; invalid relocation section index: 99 @@ -20,7 +23,6 @@ Section Details: Custom: - name: "reloc.BAD" - - relocations for section: 99 () [0] Code Disassembly: