{"record":{"id":"b0d13d7584abbd2f","repo":"tracel-ai/burn","slug":"hammingwindow-size-doesn-t-fit-in-i64-range","errorCode":null,"errorMessage":"HammingWindow size doesn't fit in i64 range.","messagePattern":"HammingWindow size doesn't fit in i64 range\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/tensor/signal/hamming_window.rs","lineNumber":51,"sourceCode":"pub fn hamming_window(\n    size: usize,\n    periodic: bool,\n    options: impl Into<TensorCreationOptions>,\n) -> Tensor<1> {\n    let opt = options.into();\n    let dtype = opt.resolve_dtype::<Float>();\n    let shape = [size];\n    check!(TensorCheck::creation_ops::<1>(\"HammingWindow\", &shape));\n\n    if size == 0 {\n        return Tensor::<1>::empty(shape, opt).cast(dtype);\n    }\n\n    if size == 1 {\n        return Tensor::<1>::ones(shape, opt).cast(dtype);\n    }\n\n    let size_i64 = i64::try_from(size).expect(\"HammingWindow size doesn't fit in i64 range.\");\n    let denominator = if periodic { size } else { size - 1 };\n    let angular_increment = (2.0 * core::f64::consts::PI) / denominator as f64;\n\n    let alpha = 25.0_f64 / 46.0_f64;\n    let beta = 1.0 - alpha;\n\n    Tensor::<1, Int>::arange(0..size_i64, &opt.device)\n        .float()\n        .mul_scalar(angular_increment)\n        .cos()\n        .mul_scalar(-beta)\n        .add_scalar(alpha)\n        .cast(dtype)\n}\n","sourceCodeStart":33,"sourceCodeEnd":66,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/tensor/signal/hamming_window.rs#L33-L66","documentation":"Same overflow guard as blackman_window but for hamming_window: the function converts the usize window size to i64 to build the arange tensor, panicking with this message if the value exceeds the i64 range.","triggerScenarios":"Calling `hamming_window(size)` with size > i64::MAX; a size computed from overflowing arithmetic (bad hop/length math in an audio pipeline); fuzz or adversarial config inputs.","commonSituations":"Audio DSP configs with corrupted window-length parameters; derived sizes from sample-rate arithmetic that wrap; generic parameter sweeps constructing windows from counters.","solutions":["Validate the size fits in i64 before calling hamming_window","Cap the window length to a practical maximum in configuration parsing","Fix the upstream size computation to avoid overflow","Reuse the sanity check that sizes >= 2 within i64 range are handled normally"],"exampleFix":"// before\nlet w = hamming_window(size, periodic, device);\n// after\nlet size_i64 = i64::try_from(size).context(\"invalid window size\")?;\nlet w = hamming_window(size_i64 as usize, periodic, device);","handlingStrategy":"validation","validationCode":"if size > (i64::MAX as usize) {\n    return Err(\"Hamming window size too large\".into());\n}\nlet w = hamming_window(size, periodic, device);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate audio window lengths against max frame sizes","Use i64::try_from with handled errors when bridging usize/i64 sizes","Sanitize DSP config values before constructing windows"],"tags":["signal","overflow","panic","burn-tensor"],"backgroundTag":"integer-overflow","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}