summaryrefslogtreecommitdiff
path: root/decode.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-15 19:49:46 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-16 00:05:35 -0600
commit6476b9ae7019bedd9324786ff47bc25693e01b60 (patch)
tree3d793bbd40327d20ba7021459862c895cddb5fb2 /decode.go
parent54bbd1e59317a6e9658eb8098657078cc8e81979 (diff)
Push nesting-depth checks down in to the parser [ci-skip]
Diffstat (limited to 'decode.go')
-rw-r--r--decode.go15
1 files changed, 5 insertions, 10 deletions
diff --git a/decode.go b/decode.go
index e4fdd77..b1cc90f 100644
--- a/decode.go
+++ b/decode.go
@@ -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]