Skip to content

Commit

Permalink
Merge branch 'master' into rc/v1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu authored Oct 12, 2023
2 parents 56df07b + 2a86c45 commit 90bbc08
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2 deletions.
30 changes: 30 additions & 0 deletions test/contracts/bad-recursive/bad-recursive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
typedef unsigned char byte;
typedef unsigned int i32;
typedef unsigned long long i64;
typedef unsigned int bigInt;

bigInt bigIntNew(long long value);
void bigIntFinishUnsigned(bigInt reference);

void init()
{
}

i64 doStackoverflow(i64 a)
{
if (a % 2 == 0)
{
return 42;
}

i64 x = doStackoverflow(a * 8 + 1);
i64 y = doStackoverflow(a * 2 + 1);
return x + y + a;
}

void badRecursive()
{
i64 result = doStackoverflow(1);
bigInt resultBig = bigIntNew(result);
bigIntFinishUnsigned(resultBig);
}
2 changes: 2 additions & 0 deletions test/contracts/bad-recursive/bad-recursive.export
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
init
badRecursive
Binary file not shown.
31 changes: 31 additions & 0 deletions vmhost/hosttest/bad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,34 @@ func testBadContractExtraLongIntLoop(t *testing.T, executorFactory executor.Exec
require.FailNow(t, "test timed out")
}
}

func TestBadContractExtra_NoPanic_BadRecursive(t *testing.T) {
if testing.Short() {
t.Skip("not a short test")
}

testCase := test.BuildInstanceCallTest(t).
WithWasmerSIGSEGVPassthrough(false).
WithContracts(
test.CreateInstanceContract(test.ParentAddress).
WithCode(test.GetTestSCCode("bad-recursive", "../../")).
WithBalance(1000)).
WithExecutorFactory(wasmer2.ExecutorFactory())

input := test.CreateTestContractCallInputBuilder().
WithRecipientAddr(test.ParentAddress).
WithGasProvided(10000000).
WithFunction("badRecursive").
Build()

repetitions := 25_000

for i := 0; i < repetitions; i++ {
testCase.
WithInput(input).
AndAssertResultsWithoutReset(func(host vmhost.VMHost, stubBlockchainHook *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) {
verify.ReturnMessage("execution failed")
verify.ExecutionFailed()
})
}
}
Binary file modified wasmer2/libvmexeccapi.dylib
Binary file not shown.
4 changes: 2 additions & 2 deletions wasmer2/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ vm_exec_result_t vm_check_signatures(vm_exec_instance_t *instance_ptr);
*
* C API function, works with raw object pointers.
*/
void vm_exec_executor_destroy(vm_exec_executor_t *executor);
void vm_exec_executor_destroy(vm_exec_executor_t *executor_ptr);

/**
* Sets the data that can be hold by an instance context.
Expand Down Expand Up @@ -380,7 +380,7 @@ vm_exec_result_t vm_exec_instance_call(vm_exec_instance_t *instance_ptr, const c
*
* C API function, works with raw object pointers.
*/
void vm_exec_instance_destroy(vm_exec_instance_t *instance);
void vm_exec_instance_destroy(vm_exec_instance_t *instance_ptr);

/**
* Creates a new VM executor instance from cache.
Expand Down
Binary file modified wasmer2/libvmexeccapi.so
Binary file not shown.

0 comments on commit 90bbc08

Please sign in to comment.