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
syscall/js: does not handle aliased pointers (panics & incorect results) #60462
Comments
This came up in arguably dubious real world code of mine however I think this could be a realistical usecase in some complex applications. Fixing this wouldn't be very hard (maintain a map of all pointers converted and reuse items of the map instead of recursing until infinity). |
package main
import "syscall/js"
func main() {
a := []any{nil}
b := []any{a, a}
js.Global().Call("foo", js.ValueOf(b))
} Also provides an incorrect result here it makes two copies of |
I'll submit a fix for this later over the week. |
This is way harder than it looks, the issue is slices, consider thoses case: a := []int{1,2,3,4,5}
b := a[2:]
return js.ValueOf([]any{a[:4:4], b})
return js.ValueOf([]any{b, a}) A simple recursive descent which memoize pointers into a map would first create a partial copy of the slice, before later then finding they need to be aliased. This could also be solved by intrinsifying |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (go1.20.4)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: