llvm.org GIT mirror llvm / 22b62da
[WebAssembly] Check function type indexes Also update tests containing invalid Wasm files, exposed by the check Differential Revision: https://reviews.llvm.org/D43954 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326577 91177308-0d34-0410-b5e6-96231b3b80d8 Nicholas Wilson 1 year, 5 months ago
3 changed file(s) with 20 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
669669 Error WasmObjectFile::parseFunctionSection(const uint8_t *Ptr, const uint8_t *End) {
670670 uint32_t Count = readVaruint32(Ptr);
671671 FunctionTypes.reserve(Count);
672 uint32_t NumTypes = Signatures.size();
672673 while (Count--) {
673 FunctionTypes.push_back(readVaruint32(Ptr));
674 uint32_t Type = readVaruint32(Ptr);
675 if (Type >= NumTypes)
676 return make_error("Invalid function type",
677 object_error::parse_failed);
678 FunctionTypes.push_back(Type);
674679 }
675680 if (Ptr != End)
676681 return make_error("Function section ended prematurely",
22 FileHeader:
33 Version: 0x00000001
44 Sections:
5 - Type: TYPE
6 Signatures:
7 - Index: 0
8 ReturnType: NORESULT
9 ParamTypes:
510 - Type: FUNCTION
611 FunctionTypes: [ 0, 0 ]
712 - Type: GLOBAL
22 FileHeader:
33 Version: 0x00000001
44 Sections:
5 - Type: TYPE
6 Signatures:
7 - Index: 0
8 ReturnType: NORESULT
9 ParamTypes:
10 - Index: 1
11 ReturnType: NORESULT
12 ParamTypes:
13 - I32
514 - Type: FUNCTION
615 FunctionTypes: [ 1, 0 ]
716 ...