fix(engine): prevent Files.Lines panic on empty file (backport to v3) - #32303
Merged
TerryHowe merged 1 commit intoJul 28, 2026
Merged
Conversation
Files.Lines guards against a nil entry but an empty file inside a chart is stored as a non-nil zero-length byte slice, so the trailing newline check indexes s[-1] and panics. The engine recovers the panic into a render error, making every template/install/upgrade/lint that references the file fail. Extend the guard to len(f[path]) == 0 and return an empty slice, matching the behaviour for missing files. Fixes helm#32279 Signed-off-by: Mahesh Sadupalli <mahesh.sadupalli@gmail.com>
|
Promptless prepared a documentation update related to this change. Triggered by helm/helm PR #32303 This PR fixes a user-visible panic in the |
gjenkins8
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #32290 to
dev-v3.Problem
Files.Linesguards against a nil entry (f[path] == nil) but an empty file inside a chart archive is stored as a non-nil zero-length[]byte. The guard passes, the code then indexess[len(s)-1]to strip a trailing newline, and panics with an index-out-of-range. The engine recovers the panic into a render error, so everyhelm install,helm upgrade, orhelm lintthat references an empty file with{{ .Files.Lines ... }}fails.Fix
Change the guard from
f[path] == niltolen(f[path]) == 0, returning an empty slice for both missing and empty files (matching the documented behaviour for missing files).Tests
Three new table-driven cases:
"")"\n")[""]— one empty elementTests verified red on unfixed code (panic recovered as "index out of range"), green on fixed code.
Relation to main
This is a direct cherry-pick of the same commit from #32290 (targeting
main). Cherry-pick applied cleanly with no conflicts. Requested as a v3 backport because the v3 bug-fix window closes today (8 July 2026).