@@ -911,8 +911,11 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
911
911
var maxIgnoreNestingDepth = 10000
912
912
913
913
// decIgnoreOpFor returns the decoding op for a field that has no destination.
914
- func (dec * Decoder ) decIgnoreOpFor (wireId typeId , inProgress map [typeId ]* decOp , depth int ) * decOp {
915
- if depth > maxIgnoreNestingDepth {
914
+ func (dec * Decoder ) decIgnoreOpFor (wireId typeId , inProgress map [typeId ]* decOp ) * decOp {
915
+ // Track how deep we've recursed trying to skip nested ignored fields.
916
+ dec .ignoreDepth ++
917
+ defer func () { dec .ignoreDepth -- }()
918
+ if dec .ignoreDepth > maxIgnoreNestingDepth {
916
919
error_ (errors .New ("invalid nesting depth" ))
917
920
}
918
921
// If this type is already in progress, it's a recursive type (e.g. map[string]*T).
@@ -938,23 +941,23 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp,
938
941
errorf ("bad data: undefined type %s" , wireId .string ())
939
942
case wire .ArrayT != nil :
940
943
elemId := wire .ArrayT .Elem
941
- elemOp := dec .decIgnoreOpFor (elemId , inProgress , depth + 1 )
944
+ elemOp := dec .decIgnoreOpFor (elemId , inProgress )
942
945
op = func (i * decInstr , state * decoderState , value reflect.Value ) {
943
946
state .dec .ignoreArray (state , * elemOp , wire .ArrayT .Len )
944
947
}
945
948
946
949
case wire .MapT != nil :
947
950
keyId := dec .wireType [wireId ].MapT .Key
948
951
elemId := dec .wireType [wireId ].MapT .Elem
949
- keyOp := dec .decIgnoreOpFor (keyId , inProgress , depth + 1 )
950
- elemOp := dec .decIgnoreOpFor (elemId , inProgress , depth + 1 )
952
+ keyOp := dec .decIgnoreOpFor (keyId , inProgress )
953
+ elemOp := dec .decIgnoreOpFor (elemId , inProgress )
951
954
op = func (i * decInstr , state * decoderState , value reflect.Value ) {
952
955
state .dec .ignoreMap (state , * keyOp , * elemOp )
953
956
}
954
957
955
958
case wire .SliceT != nil :
956
959
elemId := wire .SliceT .Elem
957
- elemOp := dec .decIgnoreOpFor (elemId , inProgress , depth + 1 )
960
+ elemOp := dec .decIgnoreOpFor (elemId , inProgress )
958
961
op = func (i * decInstr , state * decoderState , value reflect.Value ) {
959
962
state .dec .ignoreSlice (state , * elemOp )
960
963
}
@@ -1115,7 +1118,7 @@ func (dec *Decoder) compileSingle(remoteId typeId, ut *userTypeInfo) (engine *de
1115
1118
func (dec * Decoder ) compileIgnoreSingle (remoteId typeId ) * decEngine {
1116
1119
engine := new (decEngine )
1117
1120
engine .instr = make ([]decInstr , 1 ) // one item
1118
- op := dec .decIgnoreOpFor (remoteId , make (map [typeId ]* decOp ), 0 )
1121
+ op := dec .decIgnoreOpFor (remoteId , make (map [typeId ]* decOp ))
1119
1122
ovfl := overflow (dec .typeString (remoteId ))
1120
1123
engine .instr [0 ] = decInstr {* op , 0 , nil , ovfl }
1121
1124
engine .numInstr = 1
@@ -1160,7 +1163,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
1160
1163
localField , present := srt .FieldByName (wireField .Name )
1161
1164
// TODO(r): anonymous names
1162
1165
if ! present || ! isExported (wireField .Name ) {
1163
- op := dec .decIgnoreOpFor (wireField .Id , make (map [typeId ]* decOp ), 0 )
1166
+ op := dec .decIgnoreOpFor (wireField .Id , make (map [typeId ]* decOp ))
1164
1167
engine .instr [fieldnum ] = decInstr {* op , fieldnum , nil , ovfl }
1165
1168
continue
1166
1169
}
0 commit comments