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: decoding []byte into other uint sizes results in a panic #2662

Closed
rogpeppe opened this issue Jan 6, 2012 · 3 comments
Closed

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Jan 6, 2012

The following code panics - it should return an error, at the least.
4a8268927758+ weekly/weekly.2011-12-22

package main

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

func main() {
    var buf bytes.Buffer
    enc := gob.NewEncoder(&buf)
    enc.Encode([]byte("hello\n"))
    dec := gob.NewDecoder(&buf)
    var b []uint32
    err := dec.Decode(&b)
    if err != nil {
        fmt.Println("error: ", err)
        return
    }
    fmt.Printf("%v\n", b)
}

i get this result:

panic: interface conversion: gob.gobType is *gob.CommonType, not *gob.sliceType
[recovered]
    panic: interface conversion: interface is *runtime.TypeAssertionError, not gob.gobError

goroutine 1 [running]:
encoding/gob.catchError(0xf8400230b8, 0x7fe3a1da5100)
    /home/rog/go/src/pkg/encoding/gob/error.go:36 +0x67
----- stack segment boundary -----
encoding/gob.(*Decoder).compatibleType(0xf8400230006.out: exit 2
, 0xf840020000, 0x4653e8, 0xf800000005, 0xf84000dae0, ...)
    /home/rog/go/src/pkg/encoding/gob/decode.go:1042 +0x604
encoding/gob.(*Decoder).compileSingle(0xf840023000, 0x7fe300000005, 0xf8400251b0,
0xf84000db00, 0x0, ...)
    /home/rog/go/src/pkg/encoding/gob/decode.go:1070 +0x12c
encoding/gob.(*Decoder).compileDec(0xf840023000, 0xf800000005, 0xf8400251b0,
0xf84001a1e8, 0x0, ...)
    /home/rog/go/src/pkg/encoding/gob/decode.go:1103 +0x780
encoding/gob.(*Decoder).getDecEnginePtr(0xf840023000, 0x5, 0xf8400251b0, 0xf84001a1e8,
0x0, ...)
    /home/rog/go/src/pkg/encoding/gob/decode.go:1160 +0x16f
encoding/gob.(*Decoder).decodeValue(0xf840023000, 0xf800000005, 0x4653e8, 0xf840002590,
0x160, ...)
    /home/rog/go/src/pkg/encoding/gob/decode.go:1205 +0xf9
encoding/gob.(*Decoder).DecodeValue(0xf840023000, 0x4653e8, 0xf840002590, 0x160, 0x0,
...)
    /home/rog/go/src/pkg/encoding/gob/decoder.go:206 +0x123
encoding/gob.(*Decoder).Decode(0xf840023000, 0x4653d8, 0xf840002590, 0xf840002590,
0xf840021000, ...)
    /home/rog/go/src/pkg/encoding/gob/decoder.go:183 +0x165
main.main()
    /home/rog/src/tst.go:15 +0x155
@rogpeppe
Copy link
Contributor Author

rogpeppe commented Jan 6, 2012

Comment 1:

sorry, i forgot to add "gob:" at the start of the title, and i can't change it now.

@snaury
Copy link
Contributor

snaury commented Jan 6, 2012

Comment 3:

I submitted a fix here: http://golang.org/cl/5515050

@robpike
Copy link
Contributor

robpike commented Jan 9, 2012

Comment 4:

This issue was closed by revision 793768e.

Status changed to Fixed.

@mikioh mikioh changed the title gob: decoding []byte into other uint sizes results in a panic encoding/gob: decoding []byte into other uint sizes results in a panic Feb 26, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
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