sharkdp/hexyl · error

ByteOffsetParseError::UnitMultiplicationOverflow

Error message

ByteOffsetParseError::UnitMultiplicationOverflow

What it means

Multiplying the parsed number by the unit multiplier overflows i64 (e.g. a huge value times GiB). ByteOffsetParseError::UnitMultiplicationOverflow is wrapped in anyhow! and thrown.

Solutions

  1. Reduce the number or use a smaller unit so the product fits in i64
  2. Compute the exact byte value yourself and pass it in plain bytes
  3. Clamp or validate sizes in the calling script before invoking

Example fix

// before
b3sum --block-size 99999999999999999999G file
// after
b3sum --block-size 1G file
Defensive patterns

Strategy: validation

Validate before calling

python3 -c "import sys; n,u=sys.argv[1],{'G':10**9}; v=int(n)*u[u[-1]]; assert v < 2**63" 99999999999G || echo overflow

Prevention

When it happens

Trigger: --block-size with a large number and large unit, e.g. --block-size 99999999999G or any num*multiplier > i64::MAX.

Common situations: Typos adding extra digits; passing byte counts as raw u64 from scripts that exceed i64; confusion between k/M/G multipliers.

Related errors


AI-assisted analysis of sharkdp/hexyl@6ecc29b9c8 (2026-09-09). Data as JSON: /api/errors/79520d96ee9ecf85. Report an issue: GitHub.

Appendix: source

Thrown at src/main.rs:317

    };

    if let Some(hex_number) = try_parse_as_hex_number(&opt.block_size) {
        return hex_number
            .map_err(|e| anyhow!(e))
            .and_then(|x| {
                PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
            })
            .map(|_| ());
    }
    let (num, unit) = extract_num_and_unit_from(&opt.block_size)?;
    if let Unit::Block { custom_size: _ } = unit {
        return Err(anyhow!(
            "can not use 'block(s)' as a unit to specify block size"
        ));
    };
    let block_size = num
        .checked_mul(unit.get_multiplier())
        .ok_or_else(|| anyhow!(ByteOffsetParseError::UnitMultiplicationOverflow))
        .and_then(|x| {
            PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
        })?;

    let skip_arg = opt
        .skip
        .as_ref()
        .map(|s| {
            parse_byte_offset(s, block_size).context(anyhow!(
                "failed to parse `--skip` arg {:?} as byte count",
                s
            ))
        })
        .transpose()?;

    let skip_offset = if let Some(ByteOffset { kind, value }) = skip_arg {
        let value = value.into_inner();
        reader

View on GitHub (pinned to 6ecc29b9c8)