diff options
author | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-02 14:35:29 +0000 |
---|---|---|
committer | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-02 14:35:29 +0000 |
commit | 3b82510523f6c7e985271acaa7fbce72ba990775 (patch) | |
tree | 8c3dffffd2ad3ec36d2902e71bbfefc747fd9c1b /llvm/lib/Object/WasmObjectFile.cpp | |
parent | 9cc67133a147898183dd61164b972283c8358414 (diff) | |
download | llvm-3b82510523f6c7e985271acaa7fbce72ba990775.zip llvm-3b82510523f6c7e985271acaa7fbce72ba990775.tar.gz llvm-3b82510523f6c7e985271acaa7fbce72ba990775.tar.bz2 |
[WebAssembly] Check function type indexes
Also update tests containing invalid Wasm files, exposed by the check
Differential Revision: https://reviews.llvm.org/D43954
llvm-svn: 326577
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index b47d6bb..491a4cf 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -670,8 +670,13 @@ Error WasmObjectFile::parseImportSection(const uint8_t *Ptr, const uint8_t *End) Error WasmObjectFile::parseFunctionSection(const uint8_t *Ptr, const uint8_t *End) { uint32_t Count = readVaruint32(Ptr); FunctionTypes.reserve(Count); + uint32_t NumTypes = Signatures.size(); while (Count--) { - FunctionTypes.push_back(readVaruint32(Ptr)); + uint32_t Type = readVaruint32(Ptr); + if (Type >= NumTypes) + return make_error<GenericBinaryError>("Invalid function type", + object_error::parse_failed); + FunctionTypes.push_back(Type); } if (Ptr != End) return make_error<GenericBinaryError>("Function section ended prematurely", |