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

gnovm/pkg/transpiler: mangled imports in Gno code cause a panic when generating Go code #3425

Open
odeke-em opened this issue Dec 29, 2024 · 0 comments
Labels
🐞 bug Something isn't working

Comments

@odeke-em
Copy link
Contributor

odeke-em commented Dec 29, 2024

Description

In furtherance of #3087, I am fuzzing and investigating the transpiler and when presented with this Gno program

package A
import(""//"
""/***/)

Passing it into the transpiler results in this panic

panic: invalid line number 5 (should be < 5) [recovered]
	panic: invalid line number 5 (should be < 5)

goroutine 26 [running]:
github.com/gnolang/gno/gnovm/pkg/transpiler.Transpile.func1()
	/home/emmanuel/go/src/github.com/gnolang/gno/gnovm/pkg/transpiler/transpiler.go:131 +0xae
panic({0xb30640?, 0xc0001246c0?})
	/home/emmanuel/go/src/go.googlesource.com/go/src/runtime/panic.go:787 +0x132
go/token.(*File).MergeLine(0xc00028e300, 0x63?)
	/home/emmanuel/go/src/go.googlesource.com/go/src/go/token/position.go:157 +0x1a8
go/ast.sortSpecs(0xc00025e080, 0xc0006c4dc0, {0xc000126e80, 0x2, 0x2})
	/home/emmanuel/go/src/go.googlesource.com/go/src/go/ast/import.go:210 +0xa54
go/ast.SortImports(0xc00025e080, 0xc0006c4dc0)
	/home/emmanuel/go/src/go.googlesource.com/go/src/go/ast/import.go:40 +0x5a7
go/format.Node({0xe56460, 0xc0006a5740}, 0xc00025e080, {0xb6d720?, 0xc0006c4be0?})
	/home/emmanuel/go/src/go.googlesource.com/go/src/go/format/format.go:81 +0x286
github.com/gnolang/gno/gnovm/pkg/transpiler.Transpile({0xc00044f000, 0x1f}, {0xc2c171, 0x3}, {0xc2d99e, 0x6})
	/home/emmanuel/go/src/github.com/gnolang/gno/gnovm/pkg/transpiler/transpiler.go:134 +0x5ef

where it tried to generate this Go code

// Code generated by github.com/gnolang/gno. DO NOT EDIT.

//go:build gno

//line in.gno:1:1

Expected behaviour

Not a panic

Kindly cc-ing @petar-dambovaliev @moul @jaekwon

@odeke-em odeke-em added the 🐞 bug Something isn't working label Dec 29, 2024
@odeke-em odeke-em changed the title gnovm/pkg/transpiler: mangled imports in Gno code cause a panic when generating Go code gnovm/pkg/transpiler: mangled imports in Gno code cause a panic and hung the process when generating Go code Dec 29, 2024
@odeke-em odeke-em changed the title gnovm/pkg/transpiler: mangled imports in Gno code cause a panic and hung the process when generating Go code gnovm/pkg/transpiler: mangled imports in Gno code cause a panic when generating Go code Dec 30, 2024
odeke-em added a commit to odeke-em/gno that referenced this issue Jan 8, 2025
Adds a fuzzer for Transpile, which found bugs:
* gnolang#3425
* gnolang#3426
* partially gnolang#3428

Updates gnolang#3087
odeke-em added a commit to odeke-em/gno that referenced this issue Jan 8, 2025
Adds a fuzzer for Transpile, which found bugs:
* gnolang#3425
* gnolang#3426
* partially gnolang#3428

Updates gnolang#3087
odeke-em added a commit to odeke-em/gno that referenced this issue Jan 8, 2025
Adds a fuzzer for Transpile, which found bugs:
* gnolang#3425
* gnolang#3426
* partially gnolang#3428

Updates gnolang#3087
odeke-em added a commit to odeke-em/gno that referenced this issue Jan 8, 2025
Adds a fuzzer for Transpile, which found bugs:
* gnolang#3425
* gnolang#3426
* partially gnolang#3428

Updates gnolang#3087
n2p5 added a commit that referenced this issue Jan 9, 2025
Adds a fuzzer for Transpile, which found bugs:
* #3425 in which this following Go program crashed the transpiler
```go
package A
import(""//"
""/***/)
```
* #3426 which generated an input that revealed the fact that Gno
deviates from Go by allowing unused variables yet Go's standard is
strict on unused variables like this program
```go
package main

func main() {
	const c1 = 1 < 8
	main()
	1
}
```
which we shouldn't allow
* partially #3428 which revealed the discrepancy in Gno that the
overflow detection is still lacking as the following program is invalid
Go but Gno allowed it to run
```go
package main

func main() {
	const c1 = int8(1) << 8
	println(c1)
}
```
because 1<<8 (256) is higher than the range of int8 for which the
maximum is `(1<<7) - 1 aka 127`

Updates #3087

Co-authored-by: Nathan Toups <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Status: Triage
Development

No branches or pull requests

1 participant