You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Files.Lines template helper in pkg/engine/files.go panics with "index out of range [-1]" when the referenced file is empty. The engine recovers the panic and surfaces it as a render error, but every helm template / install / upgrade / lint and every SDK Engine.Render call that hits the template fails non-zero.
Affected: helm.sh/helm/v3 from 3.13.0 onward, helm.sh/helm/v4 all releases including v4.2.0, confirmed against the main branch.
Root cause: the function checks f[path] == nil but not len(f[path]) == 0. An empty file inside a chart is stored as a non-nil zero-length byte slice. s := string(f[path]) is empty, then s[len(s)-1] panics.
How can we reproduce it (as minimally and precisely as possible)?
Proof of concept: a chart containing an empty file in files/ and a single {{ range .Files.Lines "files/empty.txt" }} block fails every render:
Build helm from the affected commit (or use any release from v3.13.0 onward, including v3.21.0 and v4.2.0):
Error: template: panicchart/templates/cm.yaml:7:16: executing "panicchart/templates/cm.yaml" at <.Files.Lines>: error calling Lines: runtime error: index out of range [-1]
Use --debug flag to render out invalid YAML
helm install --dry-run mytest ./panicchart produces the same error and exits non-zero.
Suggested fix: guard with len(f[path]) == 0 and use strings.TrimSuffix(s, "\n") instead of subscripting.
I'd like to take this one. I verified the root cause on main: files.Lines (pkg/engine/files.go) guards f == nil || f[path] == nil, but an empty file in a chart is stored as a non-nil zero-length byte slice, so s[len(s)-1] panics with index -1.
Plan:
Extend the guard to len(f[path]) == 0 and return []string{}, keeping the nil/missing-path behaviour unchanged.
Unit tests in files_test.go: empty file, file containing only a newline (the boundary the trailing-newline trim is about), and the existing non-empty cases untouched.
Target main (v4) first per the contributing guide, then open the dev-v3 backport right away, since v3 bug fixes are only accepted until July 8th 2026.
Commits will be DCO signed. Will have the PR up shortly.
Activity
SudhanshuMatrix commentedon Jul 2, 2026
Hi everyone,
I have opened a PR #32280 to address this issue
mahesh-sadupalli commentedon Jul 3, 2026
I'd like to take this one. I verified the root cause on main:
files.Lines(pkg/engine/files.go) guardsf == nil || f[path] == nil, but an empty file in a chart is stored as a non-nil zero-length byte slice, sos[len(s)-1]panics with index -1.Plan:
len(f[path]) == 0and return[]string{}, keeping the nil/missing-path behaviour unchanged.files_test.go: empty file, file containing only a newline (the boundary the trailing-newline trim is about), and the existing non-empty cases untouched.main(v4) first per the contributing guide, then open thedev-v3backport right away, since v3 bug fixes are only accepted until July 8th 2026.Commits will be DCO signed. Will have the PR up shortly.
fix(engine): prevent Files.Lines panic on empty file
fix(engine): prevent Files.Lines panic on empty file
fix(engine): prevent Files.Lines panic on empty file
ahachmann commentedon Aug 14, 2026
Is there any reason for this not being added to the new 4.2.4 Release? We were hoping it would make it in.