{"record":{"id":"09b49b2e46c93813","repo":"slint-ui/slint","slug":"attempt-to-multiply-with-overflow","errorCode":null,"errorMessage":"attempt to multiply with overflow","messagePattern":"attempt to multiply with overflow","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/renderers/software/fixed.rs","lineNumber":130,"sourceCode":"impl<T: core::ops::Mul<Output = T>, const SHIFT: usize> core::ops::Mul<T> for Fixed<T, SHIFT> {\n    type Output = Self;\n    #[inline(always)]\n    fn mul(self, rhs: T) -> Self::Output {\n        Self(self.0.mul(rhs))\n    }\n}\n\nimpl<T: core::ops::Mul<Output = T>, const SHIFT: usize> core::ops::Mul<Fixed<T, SHIFT>>\n    for Fixed<T, SHIFT>\nwhere\n    T: TryFrom<i64> + Into<i64>,\n    <T as TryFrom<i64>>::Error: core::fmt::Debug,\n{\n    type Output = Self;\n    fn mul(self, rhs: Fixed<T, SHIFT>) -> Self::Output {\n        let lhs_i64: i64 = self.0.into();\n        let rhs_i64: i64 = rhs.0.into();\n        Self(T::try_from((lhs_i64 * rhs_i64) >> SHIFT).expect(\"attempt to multiply with overflow\"))\n    }\n}\n\nimpl<T: core::ops::Neg<Output = T>, const SHIFT: usize> core::ops::Neg for Fixed<T, SHIFT> {\n    type Output = Self;\n    #[inline(always)]\n    fn neg(self) -> Self::Output {\n        Self(-self.0)\n    }\n}\n\nimpl<T: core::ops::Div<Output = T>, const SHIFT: usize> core::ops::Div for Fixed<T, SHIFT> {\n    type Output = T;\n    #[inline(always)]\n    fn div(self, rhs: Self) -> Self::Output {\n        self.0 / rhs.0\n    }\n}","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/renderers/software/fixed.rs#L112-L148","documentation":"The software renderer's fixed-point `Fixed::mul` widens both operands to `i64`, multiplies, shifts right by `SHIFT`, and converts back with `try_from().expect()`. The panic fires when the product (before or after the shift) cannot be represented in the underlying `T` (e.g. `i16`/`i32` fixed-point), i.e. an arithmetic overflow in fixed-point math. Rust's debug build turns the intermediate `lhs * rhs` multiply into its own 'attempt to multiply with overflow' panic if the i64 product itself overflows (extremely large operands).","triggerScenarios":"Multiplying two `Fixed<T, SHIFT>` values whose product exceeds `T`'s range after shifting — e.g. multiplying large layout coordinates or scale factors in the software renderer; also triggered in debug builds when `(lhs_i64 * rhs_i64)` overflows `i64` (operands near `i64::MAX`).","commonSituations":"Software-renderer users hit this with pathological geometry: enormous item sizes/offsets, huge scale transforms, or window coordinates in the billions; more common in debug builds where overflow checks are on.","solutions":["Check the geometry/transform values feeding the renderer — clamp item sizes and scale factors to sane ranges","Run in release mode (`--release`) where debug overflow assertions on the i64 multiply are off (the `try_from` still panics on T overflow)","Upgrade Slint — fixed-point overflow handling may have been widened or made saturating","Reduce window size / scaling factor (e.g. very large HiDPI multipliers) that push coordinates out of range"],"exampleFix":"// before (library code)\nSelf(T::try_from((lhs_i64 * rhs_i64) >> SHIFT).expect(\"attempt to multiply with overflow\"))\n// after (saturating alternative)\nSelf(T::try_from(((lhs_i64 * rhs_i64) >> SHIFT)).unwrap_or(T::MAX))","handlingStrategy":"validation","validationCode":"// keep geometry within fixed-point range before layout\ndebug_assert!(w < 1_000_000 && h < 1_000_000, \"geometry out of fixed-point range\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp item sizes, offsets, and scale factors to realistic ranges","Avoid extreme HiDPI scale multipliers with the software renderer","Keep overflow-check behavior in mind: test debug builds to surface overflow early","Upgrade Slint if you legitimately need larger coordinate ranges"],"tags":["renderer","software-renderer","fixed-point","overflow","rust"],"backgroundTag":"value-out-of-range","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}