Skip to content

Commit 4b212e7

Browse files
committed
Ensure __heap_base and __data_end global indices are validated against import count (bytecodealliance#3996)
1 parent 4377fd0 commit 4b212e7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5927,6 +5927,13 @@ load_from_sections(WASMModule *module, WASMSection *sections,
59275927
for (i = 0; i < module->export_count; i++, export ++) {
59285928
if (export->kind == EXPORT_KIND_GLOBAL) {
59295929
if (!strcmp(export->name, "__heap_base")) {
5930+
if (export->index < module->import_global_count) {
5931+
LOG_DEBUG("Skip the process if __heap_base is imported "
5932+
"instead of being a local global");
5933+
continue;
5934+
}
5935+
5936+
/* only process linker-generated symbols */
59305937
global_index = export->index - module->import_global_count;
59315938
global = module->globals + global_index;
59325939
if (global->type.val_type == VALUE_TYPE_I32
@@ -5941,6 +5948,13 @@ load_from_sections(WASMModule *module, WASMSection *sections,
59415948
}
59425949
}
59435950
else if (!strcmp(export->name, "__data_end")) {
5951+
if (export->index < module->import_global_count) {
5952+
LOG_DEBUG("Skip the process if __data_end is imported "
5953+
"instead of being a local global");
5954+
continue;
5955+
}
5956+
5957+
/* only process linker-generated symbols */
59445958
global_index = export->index - module->import_global_count;
59455959
global = module->globals + global_index;
59465960
if (global->type.val_type == VALUE_TYPE_I32

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,12 @@ load_from_sections(WASMModule *module, WASMSection *sections,
27362736
for (i = 0; i < module->export_count; i++, export ++) {
27372737
if (export->kind == EXPORT_KIND_GLOBAL) {
27382738
if (!strcmp(export->name, "__heap_base")) {
2739+
if (export->index < module->import_global_count) {
2740+
LOG_DEBUG("Skip the process if __heap_base is imported "
2741+
"instead of being a local global");
2742+
continue;
2743+
}
2744+
27392745
global_index = export->index - module->import_global_count;
27402746
global = module->globals + global_index;
27412747
if (global->type.val_type == VALUE_TYPE_I32
@@ -2750,6 +2756,12 @@ load_from_sections(WASMModule *module, WASMSection *sections,
27502756
}
27512757
}
27522758
else if (!strcmp(export->name, "__data_end")) {
2759+
if (export->index < module->import_global_count) {
2760+
LOG_DEBUG("Skip the process if __data_end is imported "
2761+
"instead of being a local global");
2762+
continue;
2763+
}
2764+
27532765
global_index = export->index - module->import_global_count;
27542766
global = module->globals + global_index;
27552767
if (global->type.val_type == VALUE_TYPE_I32

0 commit comments

Comments
 (0)