aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/gob/decode.go
diff options
context:
space:
mode:
authorHÃ¥vard Haugen <havard.haugen@gmail.com>2015-01-28 23:07:05 +0100
committerRob Pike <r@golang.org>2015-04-08 21:28:24 +0000
commit8e6cf5f70c77daadf1b2c798f227031be156a904 (patch)
tree91cb9fc08162baccf744ef0581f00884e2aedbab /src/encoding/gob/decode.go
parentb28802d2f1ba9ef49fc3608d7026a524a98bdddb (diff)
downloadgo-8e6cf5f70c77daadf1b2c798f227031be156a904.tar.gz
go-8e6cf5f70c77daadf1b2c798f227031be156a904.zip
encoding/gob: clean up decoderMap after errBadType
When decoding an invalid typeId the associated *decEngine was not removed from decoderMap. If the decoder was run again on the same input a nil *decEngine was found in the map and assumed to be initialized, resulting in a panic. Fixes #9649 Change-Id: I5bb51808362a21c09228c2705a658f073e5b59b3 Reviewed-on: https://go-review.googlesource.com/3509 Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/encoding/gob/decode.go')
-rw-r--r--src/encoding/gob/decode.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/encoding/gob/decode.go b/src/encoding/gob/decode.go
index f1c597086d..3f34cbac57 100644
--- a/src/encoding/gob/decode.go
+++ b/src/encoding/gob/decode.go
@@ -1051,6 +1051,7 @@ func (dec *Decoder) compileIgnoreSingle(remoteId typeId) (engine *decEngine, err
// compileDec compiles the decoder engine for a value. If the value is not a struct,
// it calls out to compileSingle.
func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEngine, err error) {
+ defer catchError(&err)
rt := ut.base
srt := rt
if srt.Kind() != reflect.Struct || ut.externalDec != 0 {
@@ -1163,8 +1164,9 @@ func (dec *Decoder) decodeValue(wireId typeId, value reflect.Value) {
value = decAlloc(value)
engine := *enginePtr
if st := base; st.Kind() == reflect.Struct && ut.externalDec == 0 {
+ wt := dec.wireType[wireId]
if engine.numInstr == 0 && st.NumField() > 0 &&
- dec.wireType[wireId] != nil && len(dec.wireType[wireId].StructT.Field) > 0 {
+ wt != nil && len(wt.StructT.Field) > 0 {
name := base.Name()
errorf("type mismatch: no fields matched compiling decoder for %s", name)
}