mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 23:57:56 +00:00
Fix potential huge allocation as a result of validate_block output (#13183)
* Fix potential huge allocation as a result of `validate_block` output * Address review comments; add more tests * Update client/executor/wasmtime/src/runtime.rs * Remove unnecessary comments Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -19,8 +19,13 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use codec::{Decode, Encode};
|
||||
use sc_executor_common::{error::Error, runtime_blob::RuntimeBlob, wasm_runtime::WasmModule};
|
||||
use sc_executor_common::{
|
||||
error::{Error, WasmError},
|
||||
runtime_blob::RuntimeBlob,
|
||||
wasm_runtime::WasmModule,
|
||||
};
|
||||
use sc_runtime_test::wasm_binary_unwrap;
|
||||
use sp_core::{
|
||||
blake2_128, blake2_256, ed25519, map,
|
||||
@@ -781,3 +786,67 @@ fn return_value(wasm_method: WasmExecutionMethod) {
|
||||
(1234u64).encode()
|
||||
);
|
||||
}
|
||||
|
||||
test_wasm_execution!(return_huge_len);
|
||||
fn return_huge_len(wasm_method: WasmExecutionMethod) {
|
||||
let mut ext = TestExternalities::default();
|
||||
let mut ext = ext.ext();
|
||||
|
||||
match call_in_wasm("test_return_huge_len", &[], wasm_method, &mut ext).unwrap_err() {
|
||||
Error::Runtime => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
|
||||
},
|
||||
Error::RuntimeConstruction(WasmError::Other(error)) => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
|
||||
assert_eq!(error, "output exceeds bounds of wasm memory");
|
||||
},
|
||||
error => panic!("unexpected error: {:?}", error),
|
||||
}
|
||||
}
|
||||
|
||||
test_wasm_execution!(return_max_memory_offset);
|
||||
fn return_max_memory_offset(wasm_method: WasmExecutionMethod) {
|
||||
let mut ext = TestExternalities::default();
|
||||
let mut ext = ext.ext();
|
||||
|
||||
assert_eq!(
|
||||
call_in_wasm("test_return_max_memory_offset", &[], wasm_method, &mut ext).unwrap(),
|
||||
().encode()
|
||||
);
|
||||
}
|
||||
|
||||
test_wasm_execution!(return_max_memory_offset_plus_one);
|
||||
fn return_max_memory_offset_plus_one(wasm_method: WasmExecutionMethod) {
|
||||
let mut ext = TestExternalities::default();
|
||||
let mut ext = ext.ext();
|
||||
|
||||
match call_in_wasm("test_return_max_memory_offset_plus_one", &[], wasm_method, &mut ext)
|
||||
.unwrap_err()
|
||||
{
|
||||
Error::Runtime => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
|
||||
},
|
||||
Error::RuntimeConstruction(WasmError::Other(error)) => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
|
||||
assert_eq!(error, "output exceeds bounds of wasm memory");
|
||||
},
|
||||
error => panic!("unexpected error: {:?}", error),
|
||||
}
|
||||
}
|
||||
|
||||
test_wasm_execution!(return_overflow);
|
||||
fn return_overflow(wasm_method: WasmExecutionMethod) {
|
||||
let mut ext = TestExternalities::default();
|
||||
let mut ext = ext.ext();
|
||||
|
||||
match call_in_wasm("test_return_overflow", &[], wasm_method, &mut ext).unwrap_err() {
|
||||
Error::Runtime => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
|
||||
},
|
||||
Error::RuntimeConstruction(WasmError::Other(error)) => {
|
||||
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
|
||||
assert_eq!(error, "output exceeds bounds of wasm memory");
|
||||
},
|
||||
error => panic!("unexpected error: {:?}", error),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user