[llvm] r326577 - [WebAssembly] Check function type indexes
Nicholas Wilson via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 06:35:29 PST 2018
Author: ncw
Date: Fri Mar 2 06:35:29 2018
New Revision: 326577
URL: http://llvm.org/viewvc/llvm-project?rev=326577&view=rev
Log:
[WebAssembly] Check function type indexes
Also update tests containing invalid Wasm files, exposed by the check
Differential Revision: https://reviews.llvm.org/D43954
Modified:
llvm/trunk/lib/Object/WasmObjectFile.cpp
llvm/trunk/test/ObjectYAML/wasm/export_section.yaml
llvm/trunk/test/ObjectYAML/wasm/function_section.yaml
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=326577&r1=326576&r2=326577&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Fri Mar 2 06:35:29 2018
@@ -670,8 +670,13 @@ Error WasmObjectFile::parseImportSection
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",
Modified: llvm/trunk/test/ObjectYAML/wasm/export_section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/wasm/export_section.yaml?rev=326577&r1=326576&r2=326577&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/wasm/export_section.yaml (original)
+++ llvm/trunk/test/ObjectYAML/wasm/export_section.yaml Fri Mar 2 06:35:29 2018
@@ -3,6 +3,11 @@
FileHeader:
Version: 0x00000001
Sections:
+ - Type: TYPE
+ Signatures:
+ - Index: 0
+ ReturnType: NORESULT
+ ParamTypes:
- Type: FUNCTION
FunctionTypes: [ 0, 0 ]
- Type: GLOBAL
Modified: llvm/trunk/test/ObjectYAML/wasm/function_section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/wasm/function_section.yaml?rev=326577&r1=326576&r2=326577&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/wasm/function_section.yaml (original)
+++ llvm/trunk/test/ObjectYAML/wasm/function_section.yaml Fri Mar 2 06:35:29 2018
@@ -3,6 +3,15 @@
FileHeader:
Version: 0x00000001
Sections:
+ - Type: TYPE
+ Signatures:
+ - Index: 0
+ ReturnType: NORESULT
+ ParamTypes:
+ - Index: 1
+ ReturnType: NORESULT
+ ParamTypes:
+ - I32
- Type: FUNCTION
FunctionTypes: [ 1, 0 ]
...
More information about the llvm-commits
mailing list