{"record":{"id":"36a1f3e17bf126a9","repo":"tracel-ai/burn","slug":"scale-factor-for-width-is-too-large","errorCode":null,"errorMessage":"Scale factor for width is too large","messagePattern":"Scale factor for width is too large","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/modules/interpolate/interpolate2d.rs","lineNumber":154,"sourceCode":"    match (output_size, scale_factor) {\n        (Some(output_size), None) => {\n            // Use provided\n            output_size\n        }\n        (None, Some(scale_factor)) => {\n            // Calculate output size based on scale factor\n            let [_, _, h, w] = input_dims;\n\n            let new_dim_h = (h as f64) * (scale_factor[0] as f64);\n\n            if new_dim_h > usize::MAX as f64 {\n                panic!(\"Scale factor for height is too large\");\n            }\n\n            let new_dim_w = (w as f64) * (scale_factor[1] as f64);\n\n            if new_dim_w > usize::MAX as f64 {\n                panic!(\"Scale factor for width is too large\");\n            }\n\n            [new_dim_h as usize, new_dim_w as usize]\n        }\n        _ => panic!(\"Either output_size or scale_factor must be provided\"),\n    }\n}\n\nimpl ModuleDisplay for Interpolate2d {\n    fn custom_settings(&self) -> Option<DisplaySettings> {\n        DisplaySettings::new()\n            .with_new_line_after_attribute(false)\n            .optional()\n    }\n\n    fn custom_content(&self, content: Content) -> Option<Content> {\n        content\n            .add_debug_attribute(\"mode\", &self.mode)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/modules/interpolate/interpolate2d.rs#L136-L172","documentation":"This panic is the width counterpart of the height overflow guard in Interpolate2d::calculate_output_size. The output width is computed as input_width * scale_factor[1] in f64, and if the result exceeds usize::MAX the library panics because it cannot be materialized as a tensor dimension. It prevents silent wrap-around when upsampling along the width axis.","triggerScenarios":"Calling Interpolate2d::forward where the config used with_scale_factor([s_h, s_w]) and (input_width as f64) * s_w > usize::MAX as f64. Concrete triggers: scale_factor[1] = f64::INFINITY, an enormous finite scale value, or a very wide input multiplied by a large scale.","commonSituations":"Swapping the order of scale values so the wrong axis gets the huge factor, config-driven scales without sanity bounds, sentinel infinity accidentally left in place, or 32-bit targets where usize::MAX is ~4.29e9 and overflows happen far sooner.","solutions":["Reduce scale_factor[1] so that input_width * scale_factor[1] fits in usize.","Use with_output_size([h, w]) with explicit target dimensions instead of a scale factor.","Validate the scale before building the config: require finite values and a sane upper bound.","Check whether the huge value belongs on the other axis (h vs w swapped) and correct the ordering."],"exampleFix":"// before\nlet cfg = Interpolate2dConfig::new().with_scale_factor([2.0, 1e30]);\n// after\nassert!(scale_w.is_finite() && scale_w < 1e6);\nlet cfg = Interpolate2dConfig::new().with_scale_factor([2.0, scale_w]);\n// or explicit target size:\nlet cfg = Interpolate2dConfig::new().with_output_size([224, 448]);","handlingStrategy":"validation","validationCode":"let new_dim_w = (w as f64) * (scale_factor[1] as f64);\nif !new_dim_w.is_finite() || new_dim_w > usize::MAX as f64 {\n    return Err(\"width scale out of range\");\n}","typeGuard":"fn valid_scale(s: f64) -> bool {\n    s.is_finite() && s > 0.0 && s <= 1e6\n}","tryCatchPattern":"let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| module.forward(input)));\nmatch result {\n    Ok(out) => out,\n    Err(_) => fallback_to_output_size_config(),\n}","preventionTips":["Double-check h/w ordering in with_scale_factor([scale_h, scale_w]) — swapped values are a common cause.","Use with_output_size([h, w]) to sidestep overflow math entirely.","Sanity-check scale factors read from external configs before constructing Interpolate2dConfig."],"tags":["rust","burn-nn","panic","numeric-overflow","interpolate2d"],"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"}