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: recursive map type causes infinite loop #1518

Closed
rogpeppe opened this issue Feb 15, 2011 · 5 comments
Closed

encoding/gob: recursive map type causes infinite loop #1518

rogpeppe opened this issue Feb 15, 2011 · 5 comments

Comments

@rogpeppe
Copy link
Contributor

The following code causes gob to go into an infinite loop
when creating the encoder. I admit it's a contrived
example, but I don't see why it should be disallowed.

package main

import (
    "bytes"
    "fmt"
    "gob"
)

type T map[string] T

var t = T{"A": T{"B":nil, "C": nil}, "D": nil}

func main() {
    var buf bytes.Buffer
    enc := gob.NewEncoder(&buf)
    err := enc.Encode(t)
    fmt.Printf("err: %v\n", err)
}
@rsc
Copy link
Contributor

rsc commented Feb 15, 2011

Comment 1:

Recursive type but not recursive data.

Owner changed to r...@golang.org.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Feb 15, 2011

Comment 2:

type T *T is all you need to trigger this.  the protection against recursion works only
for structs; it needs to be generalized. wilco

@rogpeppe
Copy link
Contributor Author

Comment 3:

yes, I was aware of that when I constructed the test case. I used  a map
type because I thought it was marginally more realistic.

@robpike
Copy link
Contributor

robpike commented Feb 23, 2011

Comment 4:

FIx out for type T *T.  Structure sliding into place to fix the map case. (Note that
recursive struct types have worked all along.)

@robpike
Copy link
Contributor

robpike commented Feb 25, 2011

Comment 5:

This issue was closed by revision c54b5d0.

Status changed to Fixed.

@mikioh mikioh changed the title gob: recursive map type causes infinite loop encoding/gob: recursive map type causes infinite loop Feb 26, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants