fix(kimi-code): reject malformed server CLI numbers#1401
Open
VectorPeak wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 1c5e27d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
No linked issue; this is a focused, reproducible CLI parser bug fix.
Problem
kimi server run --port <port>and the shared internal server option parser accepted numeric values throughNumber.parseInt(raw, 10). That is a poor fit for CLI option validation becauseparseIntis a prefix parser, not a strict decimal-integer validator: once it has read a valid numeric prefix, it stops at the first non-digit character and returns the prefix instead of rejecting the whole input.As a result, malformed values could be silently accepted:
For server options, that behavior is surprising and potentially risky. A user who mistypes a port or idle grace value would not get feedback that the input is invalid; the server could instead start with a different value than the one the user intended. This is especially visible for
--port, where a malformed value can still pass the later port-range check after being truncated, and for--idle-grace-ms, where a time-like suffix such as10mslooks readable but is reduced to10.The shared parser is also used below the direct CLI entry point, so this is not only a display or help-text issue. The loose conversion happens before the rest of the server option object is built, which means downstream server lifecycle code receives a normalized number and cannot distinguish a genuinely valid integer from a partially parsed malformed string.
The expected behavior for these server numeric options is stricter: either the entire input is a decimal integer, or the option should be rejected. That keeps CLI typos visible, preserves the existing valid cases such as
8080and1000, and avoids treating unit suffixes, decimals, or mixed strings as valid configuration.What changed
parsePortandparseIdleGraceMsto reject values unless the entire input is decimal digits and fits a safe integer.--portrange check.--portand--idle-grace-msvalues.Validation run locally:
Note: local install used
ELECTRON_SKIP_BINARY_DOWNLOAD=1/ELECTRON_SKIP_DOWNLOAD=1because the unrelated Electron postinstall binary download hitECONNRESET; this parser test path does not require the Electron binary.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.