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

encoding/gob: stack overflow #10415

Closed
dvyukov opened this issue Apr 10, 2015 · 8 comments
Closed

encoding/gob: stack overflow #10415

dvyukov opened this issue Apr 10, 2015 · 8 comments
Assignees
Milestone

Comments

@dvyukov
Copy link
Member

@dvyukov dvyukov commented Apr 10, 2015

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

@dvyukov dvyukov added this to the Go1.5 milestone Apr 10, 2015
@dvyukov dvyukov added the repo-main label Apr 10, 2015
@rsc rsc removed the repo-main label Apr 14, 2015
@osocurioso
Copy link
Contributor

@osocurioso osocurioso commented Apr 14, 2015

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.

@osocurioso
Copy link
Contributor

@osocurioso osocurioso commented Apr 15, 2015

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.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 25, 2015

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

@xaionaro
Copy link
Contributor

@xaionaro xaionaro commented Nov 25, 2015

Hello. When will be the release with this fix?

@xaionaro
Copy link
Contributor

@xaionaro xaionaro commented Nov 25, 2015

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

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 25, 2015

@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.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 25, 2015

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

@xaionaro
Copy link
Contributor

@xaionaro xaionaro commented Nov 25, 2015

Ok, thanks.

@golang golang locked and limited conversation to collaborators Nov 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.