[WebAssembly] Fix overflow for input with missing version

Differential revision: https://reviews.llvm.org/D37070

llvm-svn: 311605
This commit is contained in:
Jonas Devlieghere 2017-08-23 21:36:04 +00:00
parent 15848e5977
commit a845167dca
3 changed files with 11 additions and 1 deletions

View File

@ -203,7 +203,16 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
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<StringError>("Missing version number",
object_error::parse_failed);
return;
}
Header.Version = readUint32(Ptr);
if (Header.Version != wasm::WasmVersion) {
Err = make_error<StringError>("Bad version number",
@ -211,7 +220,6 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
return;
}
const uint8_t *Eof = getPtr(getData().size());
WasmSection Sec;
while (Ptr < Eof) {
if ((Err = readSection(Sec, Ptr, getPtr(0))))

Binary file not shown.

View File

@ -0,0 +1,2 @@
# RUN: not llvm-objdump -h %p/Inputs/WASM/missing-version.wasm 2>&1 | FileCheck %s
# CHECK: {{.*}}: Missing version number