You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
492 B
26 lines
492 B
package jx |
|
|
|
import "github.com/go-faster/errors" |
|
|
|
// limit maximum depth of nesting, as allowed by https://tools.ietf.org/html/rfc7159#section-9 |
|
const maxDepth = 10000 |
|
|
|
var errMaxDepth = errors.New("depth: maximum") |
|
|
|
func (d *Decoder) incDepth() error { |
|
d.depth++ |
|
if d.depth > maxDepth { |
|
return errMaxDepth |
|
} |
|
return nil |
|
} |
|
|
|
var errNegativeDepth = errors.New("depth: negative") |
|
|
|
func (d *Decoder) decDepth() error { |
|
d.depth-- |
|
if d.depth < 0 { |
|
return errNegativeDepth |
|
} |
|
return nil |
|
}
|
|
|