{"record":{"id":"2306a25f73424c60","repo":"nautechsystems/nautilus_trader","slug":"step-exceeds-i64-range","errorCode":null,"errorMessage":"`step` exceeds i64 range","messagePattern":"`step` exceeds i64 range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/bar.rs","lineNumber":417,"sourceCode":"    let days = step_i64\n        .checked_mul(multiplier)\n        .ok_or_else(|| invalid_interval_step(step, aggregation, \"step overflows i64 days\"))?;\n    try_duration_days(days).map_err(|e| invalid_interval_step(step, aggregation, &e.to_string()))\n}\n\nfn invalid_interval_step(step: usize, aggregation: BarAggregation, reason: &str) -> anyhow::Error {\n    anyhow::anyhow!(\n        \"Invalid step in bar_type.spec.step: {step} for aggregation={aggregation}. {reason}\"\n    )\n}\n\n/// Converts a bar specification step to `i64` for time arithmetic.\n///\n/// # Panics\n///\n/// Panics if `step` exceeds the `i64` range.\nfn step_to_i64(step: NonZeroUsize) -> i64 {\n    i64::try_from(step.get()).expect(\"`step` exceeds i64 range\")\n}\n\n/// Represents a bar aggregation specification including a step, aggregation\n/// method/rule and price type.\n#[repr(C)]\n#[derive(\n    Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize, Builder,\n)]\n#[builder(build_fn(validate = \"Self::validate\"))]\n#[serde(try_from = \"BarSpecificationFields\")]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3::pyclass(module = \"nautilus_trader.model\", from_py_object)\n)]\n#[cfg_attr(\n    feature = \"python\",\n    pyo3_stub_gen::derive::gen_stub_pyclass(module = \"nautilus_trader.model\")\n)]","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/bar.rs#L399-L435","documentation":"`step_to_i64` converts the bar aggregation step from `NonZeroUsize` to `i64` because subsequent time arithmetic operates on i64 nanosecond values. It panics if the step value is larger than i64::MAX. On 64-bit platforms this only occurs with absurdly large step values, so the panic signals a nonsensical bar specification.","triggerScenarios":"Constructing a `BarType`/`BarAggregation` specification with a step (e.g. minute, second, tick count) exceeding 9,223,372,036,854,775,807 and then calling `get_bar_interval`, `get_time_bar_start`, or `timedelta` on it.","commonSituations":"Programmatically generated bar specs where a config value or multiplier is wrong (e.g. seconds supplied in nanoseconds); user input passed unvalidated into bar aggregation step; malicious or corrupted spec deserialization.","solutions":["Validate the bar step is a realistic value (< i64::MAX, practically much smaller) before constructing the BarType","Check where the step value originates — config files, CLI args, or API input — and clamp it","Use the domain types (e.g. u32-based steps where available) so oversized values fail at construction time"],"exampleFix":"// before\nlet bar_type = BarType::new(instrument_id, step_from_config, agg, price_type);\n// after\nassert!(step_from_config <= i64::MAX as usize, \"bar step too large\");\nlet bar_type = BarType::new(instrument_id, step_from_config, agg, price_type);","handlingStrategy":"validation","validationCode":"def validate_bar_step(step: int) -> int:\n    if not (0 < step < 2**63):\n        raise ValueError(f\"bar step {step} exceeds i64 range\")\n    return step","typeGuard":null,"tryCatchPattern":"try:\n    interval = bar_type.get_interval()\nexcept Exception as e:\n    logger.error(f\"invalid bar spec step: {e}\")\n    raise ValueError(\"bar step must be a realistic positive integer\") from e","preventionTips":["Validate bar steps from config/CLI before constructing BarType","Check unit conversions (ns vs s vs count) where steps are computed","Use domain types that bound step size at construction"],"tags":["rust","panic","overflow","bar-aggregation"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}