{"id":"eb2517f307524114","repo":"BurntSushi/ripgrep","slug":"size-too-big-in","errorCode":null,"errorMessage":"size too big in '{}'","messagePattern":"size too big in '(.+?)'","errorType":"validation","errorClass":"ParseSizeError","httpStatus":null,"severity":"error","filePath":"crates/cli/src/human.rs","lineNumber":60,"sourceCode":"\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`\n/// (for gigabyte). If a size suffix is missing, then the size is interpreted\n/// as bytes. If the size is too big to fit into a `u64`, then this returns an\n/// error.\n///\n/// Additional suffixes may be added over time.","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/human.rs#L42-L78","documentation":"parse_human_readable_size returns ParseSizeErrorKind::Overflow when the suffix multiplication (checked_mul by 1<<10/1<<20/1<<30) wraps past u64::MAX. Unlike InvalidInt, the digit portion itself parsed fine; only the scaled result is too large.","triggerScenarios":"Passing a value like \"9999999999999999G\" or \"18014398509481983K\" where value * suffix-factor overflows u64 even though value alone is a valid u64.","commonSituations":"CLI/config size limits set unrealistically high with a K/M/G suffix; copy-pasted thresholds from documentation of a different tool with different overflow semantics.","solutions":["Lower the numeric portion so the scaled result fits in u64.","Drop the suffix and pass the exact byte count if you need a value near u64::MAX.","Validate that value <= u64::MAX / factor before calling, choosing an appropriate upper bound for your use case."],"exampleFix":"// before\nlet n = parse_human_readable_size(\"9999999999999999G\")?; // Overflow\n\n// after\nlet n = parse_human_readable_size(\"9999999999G\")?; // fits","handlingStrategy":"validation","validationCode":"fn scaled_fits(s: &str) -> bool {\n    let (d, suf) = s.split_at(s.bytes().take_while(|b| b.is_ascii_digit()).count());\n    let Ok(v) = d.parse::<u64>() else { return false };\n    let factor = match suf { \"\" => 1u64, \"K\" => 1<<10, \"M\" => 1<<20, \"G\" => 1<<30, _ => return false };\n    v.checked_mul(factor).is_some()\n}","typeGuard":null,"tryCatchPattern":"let n = parse_human_readable_size(input)\n    .unwrap_or_else(|e| { eprintln!(\"{e}\"); u64::MAX });","preventionTips":["Pick realistic upper bounds for size flags rather than allowing near-u64::MAX values.","Use checked_mul in your own normalization layer before calling the parser.","Validate scaled results in CLI argument parsing and error early with guidance."],"tags":["size-parsing","cli","overflow","checked-mul"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}