diff options
author | Luke Shumaker <lukeshu@datawire.io> | 2022-08-15 19:49:46 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@datawire.io> | 2022-08-16 00:05:35 -0600 |
commit | 6476b9ae7019bedd9324786ff47bc25693e01b60 (patch) | |
tree | 3d793bbd40327d20ba7021459862c895cddb5fb2 /decode.go | |
parent | 54bbd1e59317a6e9658eb8098657078cc8e81979 (diff) |
Push nesting-depth checks down in to the parser [ci-skip]
Diffstat (limited to 'decode.go')
-rw-r--r-- | decode.go | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -45,6 +45,8 @@ type Decoder struct { stack []decodeStackItem } +const maxNestingDepth = 10000 + func NewDecoder(r io.Reader) *Decoder { rr, ok := r.(io.RuneReader) if !ok { @@ -54,6 +56,9 @@ func NewDecoder(r io.Reader) *Decoder { io: &noWSRuneTypeScanner{ inner: &runeTypeScannerImpl{ inner: rr, + parser: Parser{ + MaxDepth: maxNestingDepth, + }, }, }, } @@ -70,18 +75,8 @@ func (dec *Decoder) More() bool { return e == nil && t != RuneTypeEOF } -const maxNestingDepth = 10000 - func (dec *Decoder) stackPush(par reflect.Type, idx any) { dec.stack = append(dec.stack, decodeStackItem{par, idx}) - if len(dec.stack) > maxNestingDepth { - panic(decodeError{ - Field: dec.stackStr(), - FieldParent: dec.stackParent(), - FieldName: dec.stackName(), - Err: ErrDecodeExceededMaxDepth, - }) - } } func (dec *Decoder) stackPop() { dec.stack = dec.stack[:len(dec.stack)-1] |