← Back to Pull requests

motelctl: termtext.JSON sizes its buffer by the body's length, with no sum (code scanning alert 64) #549

Open
unknown opened this pull request with 323 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 17, 2026 15:27 UTC
Author

What. termtext.JSON sizes its buffer by the body's length, with no sum, which clears code-scanning alert 64 (go/allocation-size-overflow) on #538. Into client-app.

Why. CodeQL flagged out := make([]byte, 0, len(b)+16) in motelctl/internal/termtext/text.go: an addition on the length of what io.ReadAll returned, used as an allocation size. The sum cannot overflow: the client reads at most maxBody (4 MiB) plus one byte of an answer, and refuses anything over. The 16 was only a capacity hint. But the alert stood on a pull request the owner reads in full.

The change. One line: the capacity is len(b), and append grows the slice when escapes make the output longer. Every write to the buffer goes through append or fmt.Appendf, nothing reads its capacity, and withNewline copies whatever the capacity, so what --json writes is byte for byte the same.

The builder read the rule's source against every allocation #538 adds in the non-test Go of motelctl/, liveswap/ and box/ (14 make calls): this was the only one with arithmetic in its size. CodeQL was not run here; that is a reading of the rule.

Tests. No test can fail for an overflow that cannot occur, so none was added. TestJSON and the --json tests pass unchanged. go test -race ./... in motelctl; make lint MODULES="motelctl" 0 issues for both tag sets; make tidy-check; a full-history secret scan of the branch from a plain clone.

Triage (the triage skill, loaded).

| Finding | S | O | D | Product | Size | Risk | Outcome |
|---|---|---|---|---|---|---|---|
| Code scanning: the buffer's size is a sum that "may overflow" | 1 | 1 | 1 | 1 | 1 | 1 | fix: severity 1 never clears by its product, and nothing wrong can be produced; fixed because the fix is one expression that changes no output (rule 3's cheap fix) |

Self-review, one round (an Opus reviewer that did not write it, given the diff and the bar): no finding. It confirmed no caller relies on spare capacity or on the result not aliasing the input, and that no other make in motelctl's non-test Go has arithmetic in its size. No second round: nothing to fix.

Flags for the person who merges. Not one-way. Not wide.

The bar for a review. A finding is welcome if it shows a byte of --json output that changes, a write to the buffer that could now index out of range, or another line the same rule flags. Suggestions that name no failure are weighed as features; comments on wording are welcome but are not scored.

🤖 Generated with Claude Code

Diff: 323 lines (+242 / -81) across 4 files Reviewer: copilot-pull-request-reviewer[bot] Review duration: 2m
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.42) × (1 − Review Confidence (0.26)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 323 lines diff across 4 files
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 34% · Reviewer familiarity: 35%
25%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.346
Shallow Review Depth shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #549"
general weight: 0.35
Assignees
Unassigned
Labels
risk: low confidence: 25.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.0% (MEDIUM) · Higher = larger blast radius
42.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 25.9% · Lower = rushed or shallow review
25.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 31.1% · Safe to merge
31.1%