Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent panic when min > static bound and max is less than it #1718

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
- [#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.

### Fixed

- [#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.

## 1.0.0-alpha4 - 2020-10-08

### Added
Expand Down
2 changes: 0 additions & 2 deletions lib/api/src/tunables.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions lib/c-api/tests/wasm_c_api/test-memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down