Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -203,7 +203,16 @@ object_error::parse_failed); return; } + + const uint8_t *Eof = getPtr(getData().size()); const uint8_t *Ptr = getPtr(4); + + if (Ptr + 4 > Eof) { + Err = make_error("Missing version number", + object_error::parse_failed); + return; + } + Header.Version = readUint32(Ptr); if (Header.Version != wasm::WasmVersion) { Err = make_error("Bad version number", @@ -211,7 +220,6 @@ return; } - const uint8_t *Eof = getPtr(getData().size()); WasmSection Sec; while (Ptr < Eof) { if ((Err = readSection(Sec, Ptr, getPtr(0)))) Index: test/Object/wasm-missing-version.test =================================================================== --- /dev/null +++ test/Object/wasm-missing-version.test @@ -0,0 +1,2 @@ +# RUN: not llvm-objdump -h %p/Inputs/WASM/missing-version.wasm 2>&1 | FileCheck %s +# CHECK: {{.*}}: Missing version number