Skip to content

Avoid out-of-bounds section_starts_ read on invalid reloc index#2777

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:objdump-reloc-section-index
Jun 24, 2026
Merged

Avoid out-of-bounds section_starts_ read on invalid reloc index#2777
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:objdump-reloc-section-index

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

UBSan, wasm-objdump -x on a crafted module:

binary-reader-objdump.cc:69:12: runtime error: index 18446744073709551615 out of bounds for type 'const Offset[14]'
    #0 BinaryReaderObjdumpBase::GetSectionStart binary-reader-objdump.cc:69
    #1 BinaryReaderObjdump::OnReloc binary-reader-objdump.cc:2176

The input is a reloc.* custom section whose section index points past the last section. The base OnRelocCount spots that, sets reloc_section_ to BinarySection::Invalid (~0) and returns Error to abort the section. The details-mode override dropped that result and returned Ok, so ReadRelocSection carried on into OnReloc, where GetSectionStart(reloc_section_) reads section_starts_[(size_t)-1].

Result is not [[nodiscard]], so the dropped error built clean. Propagating it with CHECK_RESULT rejects the bad index the same way the other reader modes already do.

bad-relocs.txt used a zero relocation count, so it never reached OnReloc; gave it one entry so it covers the read.

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.
@sbc100 sbc100 merged commit 3baa263 into WebAssembly:main Jun 24, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants