@@ -4713,6 +4713,21 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
4713
4713
return false;
4714
4714
}
4715
4715
4716
+ #if WASM_ENABLE_BULK_MEMORY != 0
4717
+ static bool
4718
+ check_data_count_consistency(bool has_datacount_section, int datacount_len,
4719
+ int data_seg_len, char *error_buf,
4720
+ uint32 error_buf_size)
4721
+ {
4722
+ if (has_datacount_section && datacount_len != data_seg_len) {
4723
+ set_error_buf(error_buf, error_buf_size,
4724
+ "data count and data section have inconsistent lengths");
4725
+ return false;
4726
+ }
4727
+ return true;
4728
+ }
4729
+ #endif
4730
+
4716
4731
static bool
4717
4732
load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
4718
4733
WASMModule *module,
@@ -4736,9 +4751,9 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
4736
4751
read_leb_uint32(p, p_end, data_seg_count);
4737
4752
4738
4753
#if WASM_ENABLE_BULK_MEMORY != 0
4739
- if (has_datacount_section && data_seg_count != module->data_seg_count1) {
4740
- set_error_buf(error_buf, error_buf_size ,
4741
- "data count and data section have inconsistent lengths");
4754
+ if (!check_data_count_consistency(has_datacount_section,
4755
+ module->data_seg_count1, data_seg_count ,
4756
+ error_buf, error_buf_size)) {
4742
4757
return false;
4743
4758
}
4744
4759
#endif
@@ -5926,6 +5941,14 @@ load_from_sections(WASMModule *module, WASMSection *sections,
5926
5941
section = section->next;
5927
5942
}
5928
5943
5944
+ #if WASM_ENABLE_BULK_MEMORY != 0
5945
+ if (!check_data_count_consistency(
5946
+ has_datacount_section, module->data_seg_count1,
5947
+ module->data_seg_count, error_buf, error_buf_size)) {
5948
+ return false;
5949
+ }
5950
+ #endif
5951
+
5929
5952
module->aux_data_end_global_index = (uint32)-1;
5930
5953
module->aux_heap_base_global_index = (uint32)-1;
5931
5954
module->aux_stack_top_global_index = (uint32)-1;
0 commit comments