Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4713,6 +4713,21 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
return false;
}

#if WASM_ENABLE_BULK_MEMORY != 0
static bool
check_data_count_consistency(bool has_datacount_section, int datacount_len,
int data_seg_len, char *error_buf,
uint32 error_buf_size)
{
if (has_datacount_section && datacount_len != data_seg_len) {
set_error_buf(error_buf, error_buf_size,
"data count and data section have inconsistent lengths");
return false;
}
return true;
}
#endif

static bool
load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
WASMModule *module,
Expand All @@ -4736,9 +4751,9 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
read_leb_uint32(p, p_end, data_seg_count);

#if WASM_ENABLE_BULK_MEMORY != 0
if (has_datacount_section && data_seg_count != module->data_seg_count1) {
set_error_buf(error_buf, error_buf_size,
"data count and data section have inconsistent lengths");
if (!check_data_count_consistency(has_datacount_section,
module->data_seg_count1, data_seg_count,
error_buf, error_buf_size)) {
return false;
}
#endif
Expand Down Expand Up @@ -5926,6 +5941,14 @@ load_from_sections(WASMModule *module, WASMSection *sections,
section = section->next;
}

#if WASM_ENABLE_BULK_MEMORY != 0
if (!check_data_count_consistency(
has_datacount_section, module->data_seg_count1,
module->data_seg_count, error_buf, error_buf_size)) {
return false;
}
#endif

module->aux_data_end_global_index = (uint32)-1;
module->aux_heap_base_global_index = (uint32)-1;
module->aux_stack_top_global_index = (uint32)-1;
Expand Down
5 changes: 5 additions & 0 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,11 @@ load_from_sections(WASMModule *module, WASMSection *sections,
section = section->next;
}

#if WASM_ENABLE_BULK_MEMORY != 0
bh_assert(!has_datacount_section
|| module->data_seg_count == module->data_seg_count1);
#endif

module->aux_data_end_global_index = (uint32)-1;
module->aux_heap_base_global_index = (uint32)-1;
module->aux_stack_top_global_index = (uint32)-1;
Expand Down
Loading