Repository navigation
Fix gh skill search panic when page or limit overflows - #15007
shounakjoshi88-a11y wants to merge 2 commits into
Conversation
|
Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:
Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met. Full contribution requirements
|
gh skill search panic when page or limit overflows
There was a problem hiding this comment.
🟡 Changes recommended
API-page rounding can still overflow and silently omit results, while new regression tests fail validation or compilation on supported 32-bit targets.
3 open issues
What changed in this PR
This PR addresses #14985 by guarding pagination arithmetic in gh skill search against integer overflow, replacing reported panics with an early validation error.
Changes:
- Adds checked multiplication for command validation, result truncation, pagination, and API-page calculations.
- Reworks pagination page-count and end-index calculations to avoid overflow.
- Adds command and helper regression tests for large page and limit values.
| File | Description |
|---|---|
pkg/cmd/skills/search/search.go |
Adds overflow validation and guards pagination arithmetic. |
pkg/cmd/skills/search/search_test.go |
Adds regression coverage for overflowing page and limit inputs. |
Review effort: Balanced
| args: "terraform --page 9223372036854775807 --limit 2", | ||
| wantErr: "invalid page and limit: page 9223372036854775807 with limit 2 is out of range", |
There was a problem hiding this comment.
Good catch - those literals do not fit in a 32-bit int. Fixed in 25a8054: the three command cases now build the --page/--limit values from math.MaxInt at runtime and derive the expected message with fmt.Sprintf, so they overflow on 32-bit targets too and the file compiles everywhere.
| assert.Len(t, truncateForProcessing(skills, 2026277576509488133, 7), 5) | ||
| } | ||
|
|
||
| func TestPaginate_Overflow(t *testing.T) { | ||
| skills := make([]skillResult, 5) | ||
|
|
||
| got, totalPages := paginate(skills, 2026277576509488133, 7) |
There was a problem hiding this comment.
Good catch - those literals do not fit in a 32-bit int. Fixed in 25a8054: the helper tests now use math.MaxInt instead of a 64-bit-only literal. go vet with GOARCH=386 is clean.
| needed, overflowed := checkedProduct(displayPage, displayLimit, 3) | ||
| numPages := maxAPIPages | ||
| if !overflowed { | ||
| numPages = max((needed+searchPageSize-1)/searchPageSize, 1) |
There was a problem hiding this comment.
Good catch - the ceiling division could still overflow even when the product itself fits. Fixed in 25a8054: the page count now comes from a new apiPageCount helper that computes the ceiling as (needed-1)/searchPageSize+1, which cannot overflow, and TestAPIPageCount covers the math.MaxInt/3 boundary case (the value that overflows in int64 on a 64-bit target overflows in int32 on a 32-bit target).
|
The CI workflows on this pull request (Unit and Integration Tests, Lint, Code Scanning) are sitting in �ction_required, which I believe needs a maintainer to approve them before they can run on a fork PR. Could someone approve them when convenient? Both commits are green locally: go build ./... is clean, go test ./pkg/cmd/skills/... passes, gofmt reports no diffs, and go vet is clean for GOARCH=386 as well as the host architecture. |
|
The PR triage bot requires the linked issue to have the help wanted label, and #14985 does not carry it yet. I have asked on the issue for the label to be added - if it is easier to add the label directly, that would unblock the review. |
|
The fix for this is ready and the branch is still up ( The only missing piece is the PR triage checklist: the linked issue #14985 does not carry the For the record, the change is:
If adding the label to #14985 is not the right move, I am happy to open a fresh pull request once it is there - the branch is already pushed. And if the approach itself needs changing, please say so and I will rework it. AI tools were used to assist with the investigation and the initial patch; I reviewed and verified every line, and the test suite is run locally. |


Fixes #14985.
gh skill searchpanicked withslice bounds out of rangewhen--pageor--limitwere given values large enough to overflowint. The page and limit values are multiplied to compute slice bounds in three places:truncateForProcessing:page * limit * 3paginate:(page - 1) * limitfetchPrimaryPages:displayPage * displayLimit * 3An overflowing product wraps around to a negative number, which was then used as a slice bound:
The fix
checkedProducthelper multiplies non-negative values and reports whether the result overflowsint.truncateForProcessingkeeps every result when the working set does not fit in anint,paginatetreats an unrepresentable start index as past the end of the result set, andfetchPrimaryPagesfalls back to fetching the maximum number of API pages.paginatealso computes the page count and the end index without overflowing.Tests
TestNewCmdSearchcovers the three reported combinations: a large--page, a large--limit, and the--page/--limitpair that overflows the second calculation.TestTruncateForProcessing_OverflowandTestPaginate_Overflowcover the helpers directly.go build ./...is clean andgo test ./pkg/cmd/skills/...passes.