mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[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
This commit is contained in:
parent
d312d1153a
commit
33797c4702
@ -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) {
|
Error WasmObjectFile::parseFunctionSection(const uint8_t *Ptr, const uint8_t *End) {
|
||||||
uint32_t Count = readVaruint32(Ptr);
|
uint32_t Count = readVaruint32(Ptr);
|
||||||
FunctionTypes.reserve(Count);
|
FunctionTypes.reserve(Count);
|
||||||
|
uint32_t NumTypes = Signatures.size();
|
||||||
while (Count--) {
|
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)
|
if (Ptr != End)
|
||||||
return make_error<GenericBinaryError>("Function section ended prematurely",
|
return make_error<GenericBinaryError>("Function section ended prematurely",
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
FileHeader:
|
FileHeader:
|
||||||
Version: 0x00000001
|
Version: 0x00000001
|
||||||
Sections:
|
Sections:
|
||||||
|
- Type: TYPE
|
||||||
|
Signatures:
|
||||||
|
- Index: 0
|
||||||
|
ReturnType: NORESULT
|
||||||
|
ParamTypes:
|
||||||
- Type: FUNCTION
|
- Type: FUNCTION
|
||||||
FunctionTypes: [ 0, 0 ]
|
FunctionTypes: [ 0, 0 ]
|
||||||
- Type: GLOBAL
|
- Type: GLOBAL
|
||||||
|
@ -3,6 +3,15 @@
|
|||||||
FileHeader:
|
FileHeader:
|
||||||
Version: 0x00000001
|
Version: 0x00000001
|
||||||
Sections:
|
Sections:
|
||||||
|
- Type: TYPE
|
||||||
|
Signatures:
|
||||||
|
- Index: 0
|
||||||
|
ReturnType: NORESULT
|
||||||
|
ParamTypes:
|
||||||
|
- Index: 1
|
||||||
|
ReturnType: NORESULT
|
||||||
|
ParamTypes:
|
||||||
|
- I32
|
||||||
- Type: FUNCTION
|
- Type: FUNCTION
|
||||||
FunctionTypes: [ 1, 0 ]
|
FunctionTypes: [ 1, 0 ]
|
||||||
...
|
...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user