loader: Sub local count can be 0 (#1504)

Sub local count is allowed to be 0 in each group of function local types.
This commit is contained in:
Wenyong Huang 2022-09-20 12:40:24 +08:00 committed by GitHub
parent 046f5f2212
commit 64c0b15c52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -1950,8 +1950,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
local_type_index = 0;
for (j = 0; j < local_set_count; j++) {
read_leb_uint32(p_code, buf_code_end, sub_local_count);
if (!sub_local_count
|| local_type_index > UINT32_MAX - sub_local_count
/* Note: sub_local_count is allowed to be 0 */
if (local_type_index > UINT32_MAX - sub_local_count
|| local_type_index + sub_local_count > local_count) {
set_error_buf(error_buf, error_buf_size,
"invalid local count");

View File

@ -1013,8 +1013,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
local_type_index = 0;
for (j = 0; j < local_set_count; j++) {
read_leb_uint32(p_code, buf_code_end, sub_local_count);
bh_assert(sub_local_count
&& local_type_index <= UINT32_MAX - sub_local_count
/* Note: sub_local_count is allowed to be 0 */
bh_assert(local_type_index <= UINT32_MAX - sub_local_count
&& local_type_index + sub_local_count <= local_count);
CHECK_BUF(p_code, buf_code_end, 1);