@@ -60,6 +60,20 @@ interface ModelInspection {
6060 capabilities : ReturnType < typeof getModelCapabilities > ;
6161}
6262
63+ function parsePositiveIntegerOption (
64+ rawValue : string ,
65+ ) : number | null {
66+ const normalized = rawValue . trim ( ) ;
67+ if ( ! / ^ \d + $ / . test ( normalized ) ) {
68+ return null ;
69+ }
70+ const parsed = Number . parseInt ( normalized , 10 ) ;
71+ if ( ! Number . isSafeInteger ( parsed ) || parsed < 1 ) {
72+ return null ;
73+ }
74+ return parsed ;
75+ }
76+
6377const RETRYABLE_WRITE_CODES = new Set ( [ "EBUSY" , "EPERM" ] ) ;
6478
6579export interface ReportCommandDeps {
@@ -163,17 +177,17 @@ function parseReportArgs(args: string[]): ParsedArgsResult<ReportCliOptions> {
163177 if ( arg === "--max-accounts" ) {
164178 const value = args [ i + 1 ] ;
165179 if ( ! value ) return { ok : false , message : "Missing value for --max-accounts" } ;
166- const parsed = Number . parseInt ( value , 10 ) ;
167- if ( ! Number . isFinite ( parsed ) || parsed < 1 ) {
180+ const parsed = parsePositiveIntegerOption ( value ) ;
181+ if ( parsed === null ) {
168182 return { ok : false , message : "--max-accounts must be a positive integer" } ;
169183 }
170184 options . maxAccounts = parsed ;
171185 i += 1 ;
172186 continue ;
173187 }
174188 if ( arg . startsWith ( "--max-accounts=" ) ) {
175- const parsed = Number . parseInt ( arg . slice ( "--max-accounts=" . length ) , 10 ) ;
176- if ( ! Number . isFinite ( parsed ) || parsed < 1 ) {
189+ const parsed = parsePositiveIntegerOption ( arg . slice ( "--max-accounts=" . length ) ) ;
190+ if ( parsed === null ) {
177191 return { ok : false , message : "--max-accounts must be a positive integer" } ;
178192 }
179193 options . maxAccounts = parsed ;
@@ -182,17 +196,17 @@ function parseReportArgs(args: string[]): ParsedArgsResult<ReportCliOptions> {
182196 if ( arg === "--max-probes" ) {
183197 const value = args [ i + 1 ] ;
184198 if ( ! value ) return { ok : false , message : "Missing value for --max-probes" } ;
185- const parsed = Number . parseInt ( value , 10 ) ;
186- if ( ! Number . isFinite ( parsed ) || parsed < 1 ) {
199+ const parsed = parsePositiveIntegerOption ( value ) ;
200+ if ( parsed === null ) {
187201 return { ok : false , message : "--max-probes must be a positive integer" } ;
188202 }
189203 options . maxProbes = parsed ;
190204 i += 1 ;
191205 continue ;
192206 }
193207 if ( arg . startsWith ( "--max-probes=" ) ) {
194- const parsed = Number . parseInt ( arg . slice ( "--max-probes=" . length ) , 10 ) ;
195- if ( ! Number . isFinite ( parsed ) || parsed < 1 ) {
208+ const parsed = parsePositiveIntegerOption ( arg . slice ( "--max-probes=" . length ) ) ;
209+ if ( parsed === null ) {
196210 return { ok : false , message : "--max-probes must be a positive integer" } ;
197211 }
198212 options . maxProbes = parsed ;
0 commit comments