Skip to content

Commit d3a77bb

Browse files
committed
add validation for struct field type
1 parent 5d15f8f commit d3a77bb

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
17871787
read_uint32(buf, buf_end, j);
17881788
#if WASM_ENABLE_AOT_VALIDATOR != 0
17891789
/* an equivalence type should be before the type it refers to */
1790-
if (j > i) {
1790+
if (j >= i) {
17911791
set_error_buf(error_buf, error_buf_size, "invalid type index");
17921792
goto fail;
17931793
}
@@ -1964,6 +1964,11 @@ load_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
19641964

19651965
read_uint8(buf, buf_end, struct_type->fields[j].field_flags);
19661966
read_uint8(buf, buf_end, field_type);
1967+
if (!is_valid_field_type(field_type)) {
1968+
set_error_buf(error_buf, error_buf_size,
1969+
"invalid field type");
1970+
goto fail;
1971+
}
19671972
struct_type->fields[j].field_type = field_type;
19681973
struct_type->fields[j].field_size = field_size =
19691974
(uint8)wasm_reftype_size(field_type);

core/iwasm/common/wasm_loader_common.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ is_valid_func_type(const WASMFuncType *func_type)
179179
return true;
180180
}
181181

182+
bool
183+
is_valid_field_type(uint8 field_type)
184+
{
185+
if (is_valid_value_type(field_type) || field_type == PACKED_TYPE_I8
186+
|| field_type == PACKED_TYPE_I16)
187+
return true;
188+
return false;
189+
}
190+
182191
/*
183192
* Indices are represented as a u32.
184193
*/

core/iwasm/common/wasm_loader_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ is_valid_value_type_for_interpreter(uint8 value_tpye);
3838
bool
3939
is_valid_func_type(const WASMFuncType *func_type);
4040

41+
bool
42+
is_valid_field_type(uint8 field_type);
43+
4144
bool
4245
is_indices_overflow(uint32 import, uint32 other, char *error_buf,
4346
uint32 error_buf_size);

core/iwasm/interpreter/wasm_loader.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,10 @@ resolve_struct_type(const uint8 **p_buf, const uint8 *buf_end,
19611961
error_buf_size)) {
19621962
goto fail;
19631963
}
1964+
if (!is_valid_field_type(ref_type.ref_type)) {
1965+
set_error_buf(error_buf, error_buf_size, "invalid field type");
1966+
goto fail;
1967+
}
19641968
type->fields[i].field_type = ref_type.ref_type;
19651969
if (need_ref_type_map) {
19661970
type->ref_type_maps[j].index = i;

0 commit comments

Comments
 (0)