Skip to content

Commit

Permalink
Fix INTERP mode memory corruption in WAMR
Browse files Browse the repository at this point in the history
Thanks to @wenyongh for the patch to WawakaInterpreter

Signed-off-by: Marcela Melara <marcela.melara@intel.com>
  • Loading branch information
marcelamelara authored and cmickeyb committed Apr 9, 2020
1 parent fe16bb3 commit c58d420
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 11 deletions.
92 changes: 83 additions & 9 deletions build/tests/wawaka/memory-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,46 +76,63 @@
"expected":"1000"
},
{
"description" : "big value test {KeywordParameters}",
"description" : "big value test 2 KB",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 2000
},
"expected": "2000"
},
{
"description" : "big value test {KeywordParameters}",
"description" : "big value test 4 KB",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 4000
},
"expected": "4000"
},
{
"description" : "big value test {KeywordParameters}",
"description" : "big value test 8 KB",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 8000
},
"expected": "8000"
},
{
"description" : "big value test {KeywordParameters}",
"description" : "big value test 16 KB",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 16000
},
"expected": "16000"
},
{
"description" : "big value test 64 KB should {invert} with \"out of memory\" exception",
"description" : "big value test 32 KB",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 32000
},
"expected": "32000"
},
{
"description" : "big value test 64 KB should {invert} with WAMR \"out of memory\" exception",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 64000
},
"invert": "fail",
"expected": "internal pdo error"
},
{
"description" : "big value test 128 KB should {invert} with WAMR \"out of memory\" exception",
"MethodName": "big_value_test",
"KeywordParameters": {
"num_chars" : 128000
},
"invert": "fail",
"expected": "internal pdo error"
},
{
"description" : "deep recursion test {KeywordParameters}",
"MethodName": "deep_recursion_test",
Expand All @@ -125,23 +142,39 @@
"expected":"1000"
},
{
"description" : "big key test {KeywordParameters}",
"description" : "big key test 2 KB",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 2000
},
"expected": "2000"
},
{
"description" : "big key test {KeywordParameters}",
"description" : "big key test 4 KB",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 4000
},
"expected": "4000"
},
{
"description" : "big key test 32 KB should {invert} with \"out of memory\" exception",
"description" : "big key test 8 KB",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 8000
},
"expected": "8000"
},
{
"description" : "big key test 16 KB",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 16000
},
"expected": "16000"
},
{
"description" : "big key test 32 KB should {invert} with WAMR \"out of memory\" exception",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 32000
Expand All @@ -150,7 +183,7 @@
"expected": "internal pdo error"
},
{
"description" : "big key test 64 KB should {invert} with \"out of memory\" exception",
"description" : "big key test 64 KB should {invert} with WAMR \"out of memory\" exception",
"MethodName": "big_key_test",
"KeywordParameters": {
"num_chars" : 64000
Expand Down Expand Up @@ -190,6 +223,38 @@
},
"expected": "4000"
},
{
"description" : "many keys test 8K",
"MethodName": "many_keys_test",
"KeywordParameters": {
"num_keys" : 8000
},
"expected": "8000"
},
{
"description" : "many keys test 16K",
"MethodName": "many_keys_test",
"KeywordParameters": {
"num_keys" : 16000
},
"expected": "16000"
},
{
"description" : "many keys test 32K",
"MethodName": "many_keys_test",
"KeywordParameters": {
"num_keys" : 32000
},
"expected": "32000"
},
{
"description" : "many keys test 64K",
"MethodName": "many_keys_test",
"KeywordParameters": {
"num_keys" : 64000
},
"expected": "64000"
},
{
"description" : "deep recursion test {KeywordParameters}",
"MethodName": "deep_recursion_test",
Expand Down Expand Up @@ -225,6 +290,15 @@
},
"expected": "100000"
},
{
"description" : "many KV pairs test 1K * 1K",
"MethodName": "many_kv_pairs_test",
"KeywordParameters": {
"num_keys" : 1000,
"num_chars" : 1000
},
"expected": "1000000"
},
{
"description" : "deep recursion test {KeywordParameters}",
"MethodName": "deep_recursion_test",
Expand Down
7 changes: 5 additions & 2 deletions common/interpreter/wawaka_wasm/WawakaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ void WawakaInterpreter::load_contract_code(
const std::string& code)
{
char error_buf[128];
ByteArray binary_code = Base64EncodedStringToByteArray(code);
binary_code_ = Base64EncodedStringToByteArray(code);

SAFE_LOG(PDO_LOG_DEBUG, "initialize the wasm interpreter");
wasm_module = wasm_runtime_load((uint8*)binary_code.data(), binary_code.size(), error_buf, sizeof(error_buf));
wasm_module = wasm_runtime_load((uint8*)binary_code_.data(), binary_code_.size(), error_buf, sizeof(error_buf));
if (wasm_module == NULL)
SAFE_LOG(PDO_LOG_CRITICAL, "load failed with error <%s>", error_buf);

Expand Down Expand Up @@ -262,6 +262,9 @@ int32 WawakaInterpreter::evaluate_function(
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void WawakaInterpreter::Finalize(void)
{
// Clear the code buffer
binary_code_.clear();

// Destroy the environment
if (wasm_exec_env != NULL)
{
Expand Down
1 change: 1 addition & 0 deletions common/interpreter/wawaka_wasm/WawakaInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class WawakaInterpreter : public pc::ContractInterpreter
wasm_module_t wasm_module = NULL;
wasm_module_inst_t wasm_module_inst = NULL;
wasm_exec_env_t wasm_exec_env = NULL;
ByteArray binary_code_;

void parse_response_string(
int32 response_app,
Expand Down

0 comments on commit c58d420

Please sign in to comment.