-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Panic on encoding struct in a loop #293
Comments
Thank you for the reporting ! Looking at the stacktrace, it looks like you have the |
Thanks for getting back to me so quickly. During working on the reproduction, I found out that this issue only happens on |
Thank you for providing me with more detailed information.
Oh..., If the Windows environment is the cause of this problem, it can be difficult to investigate ( currently, I don't have a Windows ) For the time being, I will check if it can be reproduced on my local environment ( macOS ) . |
I think I finally have a clue to what is happening here: go-json/internal/encoder/vm/vm.go Line 4360 in d1195df
The above line is trying to create a ptr to an uint64 , however, my underlying datatype is only an int32 or uint32 .Therefore, in some cases near the edges of the buffers, the pointer might point half to the int32 , whilst the second 32 bits referenced by the pointer are unallocated memory.
I suppose the same problem would occur with all int types of less than 64 bits. |
I was running code at this issue, so if it helps, here is code to reproduce with magic numbers from a non-panic and panic: package main
import (
"fmt"
"unsafe"
)
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
func main() {
fmt.Println("won't panic:", ptrToUint64(824633827884))
fmt.Println("will panic:", ptrToUint64(824650285056))
} $ go run main.go
won't panic: 0
unexpected fault address 0xc000fcc000
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0xc000fcc000 pc=0x47e2cf]
goroutine 1 [running]:
runtime.throw({0x4948ee, 0xc000136000})
/usr/local/go/src/runtime/panic.go:1198 +0x71 fp=0xc000114eb8 sp=0xc000114e88 pc=0x42f971
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:742 +0x2f6 fp=0xc000114f08 sp=0xc000114eb8 pc=0x443476
main.ptrToUint64(...)
/mnt/c/Users/twocs/github/go-json-panic-repro/main.go:8
main.main()
/mnt/c/Users/twocs/github/go-json-panic-repro/main.go:13 +0x8f fp=0xc000114f80 sp=0xc000114f08 pc=0x47e2cf
runtime.main()
/usr/local/go/src/runtime/proc.go:255 +0x227 fp=0xc000114fe0 sp=0xc000114f80 pc=0x432047
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000114fe8 sp=0xc000114fe0 pc=0x45ab61
exit status 2 |
That makes sense. Thank you for providing the information ! |
I am currently experiencing a panic when encoding a struct during some JSON-testdata generation.
The testdata in this case is a repetition of the same struct being encoded 50k times.
The first 3-5k encodings work, after that I always get a panic.
Encoding with stdlib
encoding/json
works without a problem.If you need any additional information to debug this I am happy to assist.
The data being encoded (static only for testing)
Relevant Code extracts
The text was updated successfully, but these errors were encountered: