{"id":"2a644dac57369ad4","repo":"BurntSushi/ripgrep","slug":"invalid-integer-found-in-size","errorCode":null,"errorMessage":"invalid integer found in size '{}': {}","messagePattern":"invalid integer found in size '(.+?)': (.+?)","errorType":"validation","errorClass":"ParseSizeError","httpStatus":null,"severity":"error","filePath":"crates/cli/src/human.rs","lineNumber":55,"sourceCode":"        }\n    }\n}\n\nimpl std::error::Error for ParseSizeError {}\n\nimpl std::fmt::Display for ParseSizeError {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        use self::ParseSizeErrorKind::*;\n\n        match self.kind {\n            InvalidFormat => write!(\n                f,\n                \"invalid format for size '{}', which should be a non-empty \\\n                 sequence of digits followed by an optional 'K', 'M' or 'G' \\\n                 suffix\",\n                self.original\n            ),\n            InvalidInt(ref err) => write!(\n                f,\n                \"invalid integer found in size '{}': {}\",\n                self.original, err\n            ),\n            Overflow => write!(f, \"size too big in '{}'\", self.original),\n        }\n    }\n}\n\nimpl From<ParseSizeError> for std::io::Error {\n    fn from(size_err: ParseSizeError) -> std::io::Error {\n        std::io::Error::new(std::io::ErrorKind::Other, size_err)\n    }\n}\n\n/// Parse a human readable size like `2M` into a corresponding number of bytes.\n///\n/// Supported size suffixes are `K` (for kilobyte), `M` (for megabyte) and `G`","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/human.rs#L37-L73","documentation":"parse_human_readable_size returns ParseSizeErrorKind::InvalidInt when the leading digit run cannot be parsed as a u64 (digits.parse::<u64>() returns Err). Because the digit run is guaranteed ASCII-numeric, this in practice means the number is too large for u64, surfacing the underlying ParseIntError (kind PositiveOverflow).","triggerScenarios":"Passing a digit prefix that exceeds u64::MAX, e.g. parse_human_readable_size(\"99999999999999999999999\") — the digit slice parses but overflows u64.","commonSituations":"User pastes an enormous un-suffixed byte count, or a script generates a size string without bounds-checking; config drift where a previously-small value gained extra digits.","solutions":["Cap the numeric portion to u64::MAX (18446744073709551615) before parsing.","Use a suffix (K/M/G) to express large values compactly instead of a giant raw digit run.","Validate the input length and reject digit runs longer than 20 characters before calling the parser."],"exampleFix":"// before\nlet n = parse_human_readable_size(\"99999999999999999999999\")?; // InvalidInt\n\n// after\nlet n = parse_human_readable_size(\"9999999999G\")?; // expressed with a suffix","handlingStrategy":"validation","validationCode":"fn digit_run_fits_u64(s: &str) -> bool {\n    let digits: String = s.chars().take_while(|c| c.is_ascii_digit()).collect();\n    digits.len() <= 20 && digits.parse::<u64>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"match parse_human_readable_size(input) {\n    Ok(n) => n,\n    Err(e) => { eprintln!(\"bad size: {e}\"); 0 }\n}","preventionTips":["Bound the digit-run length before parsing.","Encourage suffix usage for large values instead of huge raw numbers.","Validate numeric ranges upstream of the parser."],"tags":["size-parsing","cli","overflow","u64"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}