golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

encoding/gob: stack overflow

dvyukov opened this issue · comments

Run the following program on the following input:

package main

import (
    "encoding/gob"
    "os"
)

func main() {
    f, _ := os.Open(os.Args[1])
    d := gob.NewDecoder(f)
    d.Decode(nil)
}

https://drive.google.com/file/d/0B20Uwp8Hs1oCWEs2azE5WlNEQXc/view?usp=sharing

It crashes with:

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x558610, 0xe)
    src/runtime/panic.go:543 +0x96
runtime.newstack()
    src/runtime/stack1.go:754 +0xacd
runtime.morestack()
    src/runtime/asm_amd64.s:330 +0x82

goroutine 1 [stack growth]:
runtime.mapaccess2_fast32(0x4ef600, 0xc208014480, 0x6a, 0x0, 0x0)
    src/runtime/hashmap_fast.go:53 fp=0xc22807e208 sp=0xc22807e200
encoding/gob.(*Decoder).decIgnoreOpFor(0xc20807c000, 0xc20000006a, 0x6a)
    src/encoding/gob/decode.go:864 +0x49 fp=0xc22807e2f0 sp=0xc22807e208
encoding/gob.(*Decoder).decIgnoreOpFor(0xc20807c000, 0xc20000006a, 0x6a)
    src/encoding/gob/decode.go:897 +0x55f fp=0xc22807e3d8 sp=0xc22807e2f0
...
...additional frames elided...

I am on commit 7c37249

For reference, the test data above is equivalent to the following hex string "1dffd30201010e726563757273697665536c69636501ffd40001ffd4000007ffd40002010000".

The exact same panic can be obtained by trying to decode the recursive map or slice in TestRecursive{Map,Slice}Type in encoder_test.go to a nil pointer (i.e. replace &r2 with nil).

One suggestion for handling the panic is to stop recursion when wireId == elemId in (*Decoder).decIgnoreOpFor.

Support for recursive types was added in c54b5d0.

Sent https://golang.org/cl/8938, mostly as a better explanation of my previous comment. I'm not claiming this is the best way to solve the underlying problem, so feel free to discard it.

CL https://golang.org/cl/8942 mentions this issue.

Hello. When will be the release with this fix?

Or is there a way to get a Debian package of current Golang snapshot?

@xaionaro Please don't ask questions on closed issues. Very few people see them. See https://golang.org/wiki/Questions . Thanks.

The fix for this issue is in the Go 1.5 release.

Go 1.6. February. We don't make Debian packages.

Ok, thanks.