Fix incorrect range in ininitialize_instance.

This commit fixes a bug where the wrong destination range was used when copying
data from the module's memory initialization upon instance initialization.

This affects the on-demand allocator only when using the `uffd` feature on
Linux and when the Wasm page being initialized is not the last in the module's
initial pages.

Fixes #2784.
This commit is contained in:
Peter Huene
2021-04-02 16:12:19 -07:00
parent b7b47e380d
commit 37bb7af454
2 changed files with 23 additions and 1 deletions

View File

@@ -379,7 +379,9 @@ fn initialize_instance(
for (page_index, page) in pages.iter().enumerate() {
if let Some(data) = page {
debug_assert_eq!(data.len(), WASM_PAGE_SIZE as usize);
slice[page_index * WASM_PAGE_SIZE as usize..].copy_from_slice(data);
let start = page_index * WASM_PAGE_SIZE as usize;
let end = start + WASM_PAGE_SIZE as usize;
slice[start..end].copy_from_slice(data);
}
}
}