BurntSushi/ripgrep · error · ParseSizeError

invalid integer found in size '{}': {}

Error message

invalid integer found in size '{}': {}

What it means

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).

Source

Thrown at crates/cli/src/human.rs:55

        }
    }
}

impl std::error::Error for ParseSizeError {}

impl std::fmt::Display for ParseSizeError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        use self::ParseSizeErrorKind::*;

        match self.kind {
            InvalidFormat => write!(
                f,
                "invalid format for size '{}', which should be a non-empty \
                 sequence of digits followed by an optional 'K', 'M' or 'G' \
                 suffix",
                self.original
            ),
            InvalidInt(ref err) => write!(
                f,
                "invalid integer found in size '{}': {}",
                self.original, err
            ),
            Overflow => write!(f, "size too big in '{}'", self.original),
        }
    }
}

impl From<ParseSizeError> for std::io::Error {
    fn from(size_err: ParseSizeError) -> std::io::Error {
        std::io::Error::new(std::io::ErrorKind::Other, size_err)
    }
}

/// Parse a human readable size like `2M` into a corresponding number of bytes.
///
/// Supported size suffixes are `K` (for kilobyte), `M` (for megabyte) and `G`

View on GitHub (pinned to 3fce3b5bb0)

Solutions

  1. Cap the numeric portion to u64::MAX (18446744073709551615) before parsing.
  2. Use a suffix (K/M/G) to express large values compactly instead of a giant raw digit run.
  3. Validate the input length and reject digit runs longer than 20 characters before calling the parser.

Example fix

// before
let n = parse_human_readable_size("99999999999999999999999")?; // InvalidInt

// after
let n = parse_human_readable_size("9999999999G")?; // expressed with a suffix
Defensive patterns

Strategy: validation

Validate before calling

fn digit_run_fits_u64(s: &str) -> bool {
    let digits: String = s.chars().take_while(|c| c.is_ascii_digit()).collect();
    digits.len() <= 20 && digits.parse::<u64>().is_ok()
}

Try / catch

match parse_human_readable_size(input) {
    Ok(n) => n,
    Err(e) => { eprintln!("bad size: {e}"); 0 }
}

Prevention

When it happens

Trigger: Passing a digit prefix that exceeds u64::MAX, e.g. parse_human_readable_size("99999999999999999999999") — the digit slice parses but overflows u64.

Common situations: 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.

Related errors


AI-assisted analysis of BurntSushi/ripgrep@3fce3b5bb0 (2026-08-06). Data as JSON: /data/errors/2a644dac57369ad4.json. Report an issue: GitHub.