fix(version-ls): clamp --limit to slice length to avoid panic (#1662)#1663
Open
SAY-5 wants to merge 1 commit into
Open
fix(version-ls): clamp --limit to slice length to avoid panic (#1662)#1663SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
…#1662) When no tags match the include regexp, filteredTags is empty and the expression filteredTags[0:flags.limit] panicked with 'slice bounds out of range [:N] with capacity 0'. Guard the slice expression with a length check so an over-sized limit is silently clamped, matching the documented behaviour where limit just truncates the output. Signed-off-by: SAY-5 <say.apm35@gmail.com>
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
What
Guard the slice expression that applies the `--limit` flag in `k3d version list` so it does not panic when the limit is larger than the number of filtered tags.
Why
Closes #1662. Reproduced exactly as reported:
```
k3d version list -i '^1.333' -l 1 -o repo k3s
panic: runtime error: slice bounds out of range [:1] with capacity 0
```
Root cause: `filteredTags[0:flags.limit]` indexes the slice without checking the slice length, so any include-regexp that matches zero tags (or fewer tags than `--limit`) trips the runtime check.
Implications
CLI-only change in `cmd/root.go`. The limit now silently clamps to `len(filteredTags)`, matching the documented intent (truncate output). Added `cmd/root_test.go` covering the regression and surrounding boundary cases.