fix: reset skipped-nodes stack on getValue entry to prevent slice overflow panic [#4818]

This commit is contained in:
water 2026-08-27 19:42:00 +08:00
parent dcaa4296d1
commit 5cf02b6f7f

View File

@ -418,6 +418,14 @@ type skippedNode struct {
func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) { func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
var globalParamsCount int16 var globalParamsCount int16
// Reset the skipped-nodes stack on entry. getValue is called once per
// method tree (e.g. in the HandleMethodNotAllowed loop) reusing the same
// pooled Context stack, and the walk below grows it via a raw reslice that
// cannot exceed engine.maxSections. Without this reset the residue from a
// previous tree leaks into the next call and can panic with "slice bounds
// out of range" once the accumulated length passes the capacity.
*skippedNodes = (*skippedNodes)[:0]
walk: // Outer loop for walking the tree walk: // Outer loop for walking the tree
for { for {
prefix := n.path prefix := n.path