Skip to content

fix(mcpx/settings): ParseBytes refuses negative and overflowing byte sizes (#1697) - #4092

Merged
dezren39 merged 1 commit into
mainfrom
queue/4257-1697-parsebytes-fix
Nov 2, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/4257-1697-parsebytes-fix

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

ParseBytes in pkgs/mcpx/internal/settings/value.go now refuses negative results and magnitudes that do not fit in an int64, with an error naming the offending value (#1697). Refusing inside ParseBytes protects every caller — Validate/Normalize at apply time (file/env/flag/preset/runtime) and the direct read-time callers (Set.Bytes, built-in defaults) — so a KindBytes setting can no longer be admitted at any layer with a value that panics a consumer (make([]byte, 0, -1): makeslice: cap out of range) or silently wraps to MinInt64.

  • Overflow guard: scaled value >= 2^63 errors as size too large: "<value>".
  • Negative guard: post-conversion n < 0 errors as size must not be negative: "<value>" (also catches float→int64 conversion fallout).
  • Zero keeps its documented meaning at the guarded consumers (not part of this change).

Tests

New TestParseBytesRefusesNegativeAndOverflowingSizes (registry_test.go): -1, -5MB, -1KiB, 999999999999999999999999TB, 9223372036854775808 all error and name the value; 0 still parses; Validate for a KindBytes setting refuses the same inputs and accepts 16MB. Existing suffix table test (TestByteSizesAcceptBothDecimalAndBinarySuffixes) keeps passing.

Laptop runs (pkgs/mcpx):

  • go test ./internal/settings/ -run 'TestParseBytes|TestByteSizes' — PASS
  • go test ./internal/cli/ ./internal/daemon/ — PASS
  • go test ./internal/settings/ — the same 5 failures as clean main (verified by running clean main side by side): TestEveryDocumentHasAChapter, TestEverySettingHasAnEffectProbeOrAnExemption, TestNoUndeclaredEnvRead, TestTheEnvironmentDocIsCurrent, TestTheScriptEnvironmentIsWhatTheCodeSets — all pre-existing, unrelated (named already by triage task 5537).

Consumer audit (acceptance)

The two scanner sites (internal/cli/client.go, internal/cli/opcmd.go) pass init cap and max to bufio.Scanner.Buffer, whose effective max is the larger of the two — no valid (non-negative) value can crash there; the negative cap was the only crash vector and is now refused at parse. http.MaxBytesReader consumers take whatever Bytes() returns; with negatives unparseable, a stored value can no longer be negative through any validated path. No follow-up issue needed.

Cross-repo

mcpx also lives in dezren39/nix; the port is tracked from #1697 per the fleet cross-repo rule (see the SET-REMAINDER note on #1697 if it does not land with this PR).

Queue task 4257 (triaged by task 5164; bug confirmed by tasks 1915/5537). Coordinate with #3521 before overlapping parser edits.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 00:35
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 36 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fd2fd39-81aa-4171-a0b6-cecdb7dbe04a
Commits

Reviewing files that changed from the base of the PR and between ceba688 and 8335c28.

Files selected for processing: 2
  • pkgs/mcpx/internal/settings/registry_test.go
  • pkgs/mcpx/internal/settings/value.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T00:36:21.541218Z 8335c28 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant