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

Stack overflow when emulating code which uses generic parameters #126

Open
ElektroKill opened this issue Jun 17, 2023 · 0 comments
Open
Labels
bug Something isn't working dotnet-asmresolver Issues related to the .NET back-end powered by AsmResolver emulation Issue related to the emulation modules of Echo.

Comments

@ElektroKill
Copy link
Contributor

When using the new Echo emulator to emulate the following snippet a stack overflow exception is hit when resolving generic parameter types.

public interface ITestInterface<out T, in U> {
    public T TestMethod(U u);
}

public class TestClass : ITestInterface<int, long> {
    public static ITestInterface<int, long> Instance = new TestClass();
    
    public int TestMethod(long u) {
        return (int)u;
    }
}

public static class Usage {
    public static int Use() {
        return TestClass.Instance.TestMethod(long.MaxValue);
    }
}

Code used to initiate the emulation:

var method = module.GetAllTypes().FirstOrDefault(x => x.Name == "Usage")?.Methods.FirstOrDefault(x => x.Name == "Use");

var vm = new CilVirtualMachine(module, false);
var frame = new CallFrame(method, vm.ValueFactory);
vm.CallStack.Push(frame);

vm.Run();

Running this code results in one of the following errors occurring:
explorer_iukCU08NNj
explorer_JAWZEeBLou

@Washi1337 Washi1337 added bug Something isn't working emulation Issue related to the emulation modules of Echo. dotnet-asmresolver Issues related to the .NET back-end powered by AsmResolver labels Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dotnet-asmresolver Issues related to the .NET back-end powered by AsmResolver emulation Issue related to the emulation modules of Echo.
Projects
None yet
Development

No branches or pull requests

2 participants