|
|
@@ -4716,8 +4716,12 @@ fail:
|
|
|
|
|
|
static bool
|
|
|
load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|
|
- WASMModule *module, bool clone_data_seg,
|
|
|
- char *error_buf, uint32 error_buf_size)
|
|
|
+ WASMModule *module,
|
|
|
+#if WASM_ENABLE_BULK_MEMORY != 0
|
|
|
+ bool has_datacount_section,
|
|
|
+#endif
|
|
|
+ bool clone_data_seg, char *error_buf,
|
|
|
+ uint32 error_buf_size)
|
|
|
{
|
|
|
const uint8 *p = buf, *p_end = buf_end;
|
|
|
uint32 data_seg_count, i, mem_index, data_seg_len;
|
|
|
@@ -4733,8 +4737,7 @@ 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 ((module->data_seg_count1 != 0)
|
|
|
- && (data_seg_count != module->data_seg_count1)) {
|
|
|
+ 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");
|
|
|
return false;
|
|
|
@@ -5242,10 +5245,11 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|
|
module->name_section_buf = buf;
|
|
|
module->name_section_buf_end = buf_end;
|
|
|
p += name_len;
|
|
|
- handle_name_section(p, p_end, module, is_load_from_file_buf, error_buf,
|
|
|
- error_buf_size);
|
|
|
+ if (!handle_name_section(p, p_end, module, is_load_from_file_buf,
|
|
|
+ error_buf, error_buf_size)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
LOG_VERBOSE("Load custom name section success.");
|
|
|
- return true;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -5789,6 +5793,9 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
uint8 malloc_free_io_type = VALUE_TYPE_I32;
|
|
|
bool reuse_const_strings = is_load_from_file_buf && !wasm_binary_freeable;
|
|
|
bool clone_data_seg = is_load_from_file_buf && wasm_binary_freeable;
|
|
|
+#if WASM_ENABLE_BULK_MEMORY != 0
|
|
|
+ bool has_datacount_section = false;
|
|
|
+#endif
|
|
|
|
|
|
/* Find code and function sections if have */
|
|
|
while (section) {
|
|
|
@@ -5881,6 +5888,9 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
break;
|
|
|
case SECTION_TYPE_DATA:
|
|
|
if (!load_data_segment_section(buf, buf_end, module,
|
|
|
+#if WASM_ENABLE_BULK_MEMORY != 0
|
|
|
+ has_datacount_section,
|
|
|
+#endif
|
|
|
clone_data_seg, error_buf,
|
|
|
error_buf_size))
|
|
|
return false;
|
|
|
@@ -5890,6 +5900,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
|
|
|
if (!load_datacount_section(buf, buf_end, module, error_buf,
|
|
|
error_buf_size))
|
|
|
return false;
|
|
|
+ has_datacount_section = true;
|
|
|
break;
|
|
|
#endif
|
|
|
#if WASM_ENABLE_STRINGREF != 0
|