summaryrefslogtreecommitdiff
path: root/decode.go
diff options
context:
space:
mode:
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]