Skip to content

Commit 315b87c

Browse files
committed
check index before accessing imports.globals
1 parent 174cc9f commit 315b87c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/runtime-core/src/backing.rs

+20
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ impl LocalBacking {
149149
}]);
150150
}
151151
Initializer::GetGlobal(import_global_index) => {
152+
if import_global_index.index() >= imports.globals.len() {
153+
return Err(vec![LinkError::Generic {
154+
message: "incorrect global index for initializer".to_string(),
155+
}]);
156+
}
152157
if let Value::I32(x) = imports.globals[import_global_index].get() {
153158
x as u32
154159
} else {
@@ -205,6 +210,11 @@ impl LocalBacking {
205210
}]);
206211
}
207212
Initializer::GetGlobal(import_global_index) => {
213+
if import_global_index.index() >= imports.globals.len() {
214+
return Err(vec![LinkError::Generic {
215+
message: "incorrect global index for initializer".to_string(),
216+
}]);
217+
}
208218
if let Value::I32(x) = imports.globals[import_global_index].get() {
209219
x as u32
210220
} else {
@@ -273,6 +283,11 @@ impl LocalBacking {
273283
}]);
274284
}
275285
Initializer::GetGlobal(import_global_index) => {
286+
if import_global_index.index() >= imports.globals.len() {
287+
return Err(vec![LinkError::Generic {
288+
message: "incorrect global index for initializer".to_string(),
289+
}]);
290+
}
276291
if let Value::I32(x) = imports.globals[import_global_index].get() {
277292
x as u32
278293
} else {
@@ -326,6 +341,11 @@ impl LocalBacking {
326341
}]);
327342
}
328343
Initializer::GetGlobal(import_global_index) => {
344+
if import_global_index.index() >= imports.globals.len() {
345+
return Err(vec![LinkError::Generic {
346+
message: "incorrect global index for initializer".to_string(),
347+
}]);
348+
}
329349
if let Value::I32(x) = imports.globals[import_global_index].get() {
330350
x as u32
331351
} else {

0 commit comments

Comments
 (0)