diff --git a/CHANGELOG.md b/CHANGELOG.md index edba3e67454..df71323a073 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +- [#1718](https://github.com/wasmerio/wasmer/pull/1718) Fix panic in the API in some situations when the memory's min bound was greater than the memory's max bound. - [#1709](https://github.com/wasmerio/wasmer/pull/1709) Implement `wasm_module_name` and `wasm_module_set_name` in the Wasm(er) C API. - [#1700](https://github.com/wasmerio/wasmer/pull/1700) Implement `wasm_externtype_copy` in the Wasm C API. diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index 77c4c742cb2..2983d8042c7 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -1,5 +1,4 @@ use crate::{MemoryType, Pages, TableType}; -use more_asserts::assert_ge; use std::cmp::min; use std::sync::Arc; use target_lexicon::{OperatingSystem, PointerWidth}; @@ -67,7 +66,6 @@ impl BaseTunables for Tunables { // If the module doesn't declare an explicit maximum treat it as 4GiB. let maximum = memory.maximum.unwrap_or_else(Pages::max_value); if maximum <= self.static_memory_bound { - assert_ge!(self.static_memory_bound, memory.minimum); MemoryStyle::Static { bound: self.static_memory_bound, offset_guard_size: self.static_memory_offset_guard_size, diff --git a/lib/c-api/tests/wasm_c_api/test-memory.c b/lib/c-api/tests/wasm_c_api/test-memory.c index 3d4c8abe75d..079768df884 100644 --- a/lib/c-api/tests/wasm_c_api/test-memory.c +++ b/lib/c-api/tests/wasm_c_api/test-memory.c @@ -62,6 +62,66 @@ int main(int argc, const char *argv[]) { wasm_memorytype_delete(memtype3); wasm_memory_delete(memory3); + // ===================== + wasm_limits_t limits4 = { + .min = 0x7FFFFFFF, + .max = 0x7FFFFFFF, + }; + own wasm_memorytype_t* memtype4 = wasm_memorytype_new(&limits4); + own wasm_memory_t* memory4 = wasm_memory_new(store, memtype4); + assert(memory4 == NULL); + error = get_wasmer_error(); + printf("Found error string: %s\n", error); + assert(0 == strcmp("The minimum requested (2147483647 pages) memory is greater than the maximum allowed memory (65536 pages)", error)); + free(error); + + wasm_memorytype_delete(memtype4); + + // ===================== + wasm_limits_t limits5 = { + .min = 0x7FFFFFFF, + .max = 0x0FFFFFFF, + }; + own wasm_memorytype_t* memtype5 = wasm_memorytype_new(&limits5); + own wasm_memory_t* memory5 = wasm_memory_new(store, memtype5); + assert(memory5 == NULL); + error = get_wasmer_error(); + printf("Found error string: %s\n", error); + assert(0 == strcmp("The minimum requested (2147483647 pages) memory is greater than the maximum allowed memory (65536 pages)", error)); + free(error); + + wasm_memorytype_delete(memtype5); + + // ===================== + wasm_limits_t limits6 = { + .min = 15, + .max = 10, + }; + own wasm_memorytype_t* memtype6 = wasm_memorytype_new(&limits6); + own wasm_memory_t* memory6 = wasm_memory_new(store, memtype6); + assert(memory6 == NULL); + error = get_wasmer_error(); + printf("Found error string: %s\n", error); + assert(0 == strcmp("The memory is invalid because the maximum (10 pages) is less than the minimum (15 pages)", error)); + free(error); + + wasm_memorytype_delete(memtype6); + + // ===================== + wasm_limits_t limits7 = { + .min = 0x7FFFFFFF, + .max = 10, + }; + own wasm_memorytype_t* memtype7 = wasm_memorytype_new(&limits7); + own wasm_memory_t* memory7 = wasm_memory_new(store, memtype7); + assert(memory7 == NULL); + error = get_wasmer_error(); + printf("Found error string: %s\n", error); + assert(0 == strcmp("The minimum requested (2147483647 pages) memory is greater than the maximum allowed memory (65536 pages)", error)); + free(error); + + wasm_memorytype_delete(memtype7); + printf("Shutting down...\n"); wasm_store_delete(store); wasm_engine_delete(engine);