mirror of
https://github.com/golang/go
synced 2024-11-21 21:34:40 -07:00
encoding/gob: fix panic when decoding []byte to incompatible slice types
Fixes #2662. R=golang-dev, rogpeppe, r, r CC=golang-dev, r, rogpeppe https://golang.org/cl/5515050
This commit is contained in:
parent
41806ec26d
commit
793768e9d5
@ -1039,9 +1039,9 @@ func (dec *Decoder) compatibleType(fr reflect.Type, fw typeId, inProgress map[re
|
||||
// Extract and compare element types.
|
||||
var sw *sliceType
|
||||
if tt, ok := builtinIdToType[fw]; ok {
|
||||
sw = tt.(*sliceType)
|
||||
} else {
|
||||
sw = dec.wireType[fw].SliceT
|
||||
sw, _ = tt.(*sliceType)
|
||||
} else if wire != nil {
|
||||
sw = wire.SliceT
|
||||
}
|
||||
elem := userType(t.Elem()).base
|
||||
return sw != nil && dec.compatibleType(elem, sw.Elem, inProgress)
|
||||
|
@ -678,3 +678,11 @@ func TestUnexportedChan(t *testing.T) {
|
||||
t.Fatalf("error encoding unexported channel: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSliceIncompatibility(t *testing.T) {
|
||||
var in = []byte{1, 2, 3}
|
||||
var out []int
|
||||
if err := encAndDec(in, &out); err == nil {
|
||||
t.Error("expected compatibility error")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user