Skip to content

framework: return error instead of panicking on out-of-range array index#204

Open
c-tonneslan wants to merge 1 commit into
score-spec:mainfrom
c-tonneslan:guard-override-array-bounds
Open

framework: return error instead of panicking on out-of-range array index#204
c-tonneslan wants to merge 1 commit into
score-spec:mainfrom
c-tonneslan:guard-override-array-bounds

Conversation

@c-tonneslan

Copy link
Copy Markdown

overridePathInArray only bounds-checks the array index in the terminal (len(path) == 1) branch. When the override path continues past the index, it falls through to output[pathIndex] with no check, so an override such as volumes.3.source against a shorter array panics with index out of range (a negative index like volumes.-1.source panics too). Since --override-property values flow straight into OverridePathInMap, a typo'd index crashes the CLIs with a Go stack trace instead of the usual friendly error.

This adds the same out-of-range check the terminal branch already returns, before the type switch. Added two table cases (nested index out of range, nested negative index) that panic on main and now return cannot set 'N' in array: out of range.

Fixes #202

overridePathInArray bounds-checked the index only in the terminal
(len(path) == 1) branch. When the override path continued past the index it
indexed output[pathIndex] directly, so an override like volumes.3.source
against a shorter array panicked with "index out of range". Return the same
out-of-range error the terminal branch already returns.

Fixes score-spec#202

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@mathieu-benoit
mathieu-benoit self-requested a review July 6, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] OverridePathInMap panics with "index out of range" when an override path indexes an array out of bounds

1 participant