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

VM Crash on Type Conversion with Native Type #3006

Closed
omarsy opened this issue Oct 23, 2024 · 1 comment
Closed

VM Crash on Type Conversion with Native Type #3006

omarsy opened this issue Oct 23, 2024 · 1 comment
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@omarsy
Copy link
Member

omarsy commented Oct 23, 2024

Description

I encountered a crash in the Gno VM when performing a type conversion with a native type. The code below demonstrates the issue, where converting a struct to io.Reader causes the VM to crash during execution.

Code Snippet

package main

import "io"

type s struct{}

func (s) Read(p []byte) (n int, err error) {
	return 0, nil
}

func main() {
	var v = (io.Reader)(s{})
	println(v.Read([]byte("test")))
}

Stacktrace

runtime/debug.Stack()
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/debug/stack.go:16 +0x1c
command-line-arguments.RunFileTest.func1.1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:155 +0x1e0
panic({0x104b1ae20?, 0x1400043c900?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Stacktrace(0x1400035ed88)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:513 +0x2a4
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunMain.func1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:840 +0x124
panic({0x104add900?, 0x1400004aaa0?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
reflect.Value.assignTo({0x104b00760?, 0x1050cb580?, 0x14000428c98?}, {0x1048626d8, 0xb}, 0x104b19fa0, 0x1400004aa30)
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/reflect/value.go:3356 +0x20c
reflect.Value.Set({0x104b19fa0?, 0x1400004aa30?, 0x0?}, {0x104b00760?, 0x1050cb580?, 0x16?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/reflect/value.go:2325 +0xcc
github.com/gnolang/gno/gnovm/pkg/gnolang.gno2GoValue.func1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/gonative.go:1067 +0x54
github.com/gnolang/gno/gnovm/pkg/gnolang.gno2GoValue(0x14000432050, {0x104b19fa0?, 0x1400004aa30?, 0x1042710ec?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/gonative.go:1227 +0x9c0
github.com/gnolang/gno/gnovm/pkg/gnolang.ConvertTo(0x0, {0x104be5290, 0x14000248d20}, 0x14000432050, {0x104bd8110, 0x140004104e0?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/values_conversions.go:57 +0x180
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).doOpConvert(0x1400035ed88)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/op_expressions.go:799 +0xb0
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Run(0x1400035ed88)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:1492 +0x6c0
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunStatement(0x1400035ed88, {0x104bddd28, 0x140003f7300})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:954 +0x330
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunMain(0x1400035ed88)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:845 +0x154
command-line-arguments.RunFileTest.func1(0x7?, 0x104bcf188?, {0x14000285900?, 0x0?}, 0x140001411d0, {0x10485ebb3, 0x4}, {0x10485ebb3, 0x4}, {0x104be5290, ...}, ...)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:178 +0x7e0
command-line-arguments.RunFileTest({0x140000116c8, 0x5}, {0x140004305e8, 0x11}, {0x14000244450, 0x4, 0x6?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file.go:247 +0x238
command-line-arguments.runFileTest(0x140003e01a0, {0x140004305e8, 0x11}, {0x1400036a890, 0x2, 0x104383c98?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file_test.go:140 +0x1c8
command-line-arguments.runFileTests.func1(0x140003e01a0?)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/tests/file_test.go:64 +0x38
testing.tRunner(0x140003e01a0, 0x14000141170)
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 35
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1742 +0x318

Expected Behavior

The program should run without crashing, allowing the Read method of the io.Reader interface to execute properly.

Actual Behavior

The VM crashes with a panic related to the type conversion process.

@thehowl
Copy link
Member

thehowl commented Nov 28, 2024

named native types are no longer available as of #3119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

No branches or pull requests

3 participants