{"record":{"id":"79520d96ee9ecf85","repo":"sharkdp/hexyl","slug":"byteoffsetparseerror-unitmultiplicationoverflow","errorCode":null,"errorMessage":"ByteOffsetParseError::UnitMultiplicationOverflow","messagePattern":"ByteOffsetParseError::UnitMultiplicationOverflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":317,"sourceCode":"    };\n\n    if let Some(hex_number) = try_parse_as_hex_number(&opt.block_size) {\n        return hex_number\n            .map_err(|e| anyhow!(e))\n            .and_then(|x| {\n                PositiveI64::new(x).ok_or_else(|| anyhow!(\"block size argument must be positive\"))\n            })\n            .map(|_| ());\n    }\n    let (num, unit) = extract_num_and_unit_from(&opt.block_size)?;\n    if let Unit::Block { custom_size: _ } = unit {\n        return Err(anyhow!(\n            \"can not use 'block(s)' as a unit to specify block size\"\n        ));\n    };\n    let block_size = num\n        .checked_mul(unit.get_multiplier())\n        .ok_or_else(|| anyhow!(ByteOffsetParseError::UnitMultiplicationOverflow))\n        .and_then(|x| {\n            PositiveI64::new(x).ok_or_else(|| anyhow!(\"block size argument must be positive\"))\n        })?;\n\n    let skip_arg = opt\n        .skip\n        .as_ref()\n        .map(|s| {\n            parse_byte_offset(s, block_size).context(anyhow!(\n                \"failed to parse `--skip` arg {:?} as byte count\",\n                s\n            ))\n        })\n        .transpose()?;\n\n    let skip_offset = if let Some(ByteOffset { kind, value }) = skip_arg {\n        let value = value.into_inner();\n        reader","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/sharkdp/hexyl/blob/6ecc29b9c8c84d08a7e860f7f69c22b113b480ea/src/main.rs#L299-L335","documentation":"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.","triggerScenarios":"--block-size with a large number and large unit, e.g. --block-size 99999999999G or any num*multiplier > i64::MAX.","commonSituations":"Typos adding extra digits; passing byte counts as raw u64 from scripts that exceed i64; confusion between k/M/G multipliers.","solutions":["Reduce the number or use a smaller unit so the product fits in i64","Compute the exact byte value yourself and pass it in plain bytes","Clamp or validate sizes in the calling script before invoking"],"exampleFix":"// before\nb3sum --block-size 99999999999999999999G file\n// after\nb3sum --block-size 1G file","handlingStrategy":"validation","validationCode":"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","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanity-check magnitudes before passing huge multipliers","Use i64-safe values (< ~9.2 exabytes)"],"tags":["cli","overflow","parsing"],"backgroundTag":"argument-out-of-range","analyzedSha":"6ecc29b9c8c84d08a7e860f7f69c22b113b480ea","analyzedAt":"2026-09-09T22:34:15.450Z","contentChangedAt":"2026-09-09T22:34:15.450Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}