{"record":{"id":"a42278ddf2391f57","repo":"databendlabs/databend","slug":"i256-overflow","errorCode":null,"errorMessage":"i256 overflow","messagePattern":"i256 overflow","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/expression/src/types/decimal.rs","lineNumber":2920,"sourceCode":"\nimpl std::fmt::Debug for i256 {\n    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n        write!(f, \"{:?}\", self.0)\n    }\n}\n\nimpl std::fmt::Display for i256 {\n    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n        write!(f, \"{}\", self.0)\n    }\n}\n\nimpl Neg for i256 {\n    type Output = Self;\n\n    #[inline]\n    fn neg(self) -> Self::Output {\n        Self(self.0.checked_neg().expect(\"i256 overflow\"))\n    }\n}\n\nimpl AddAssign for i256 {\n    fn add_assign(&mut self, rhs: Self) {\n        self.0 += rhs.0;\n    }\n}\n\nimpl SubAssign for i256 {\n    fn sub_assign(&mut self, rhs: Self) {\n        self.0 -= rhs.0;\n    }\n}\n\nimpl MulAssign for i256 {\n    fn mul_assign(&mut self, rhs: Self) {\n        self.0 *= rhs.0;","sourceCodeStart":2902,"sourceCodeEnd":2938,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/expression/src/types/decimal.rs#L2902-L2938","documentation":"The Neg implementation for the 256-bit signed decimal type i256 uses checked_neg and panics on 'i256 overflow'. Negating i256::MIN (the only value whose negation is not representable in two's complement 256-bit) overflows and triggers this panic. All other i256 values negate fine.","triggerScenarios":"Computing -x where x == i256::MIN (e.g. unary minus on the most negative decimal value, or arithmetic like 0 - i256::MIN routed through Neg).","commonSituations":"Decimal arithmetic on extreme user values: a literal or computed decimal equal to the minimum 256-bit value passed through unary minus, ABS-style transformations, or negation inside aggregate/window functions.","solutions":["Check for i256::MIN before negating and return an overflow error (decimal overflow / value out of range).","Use a checked/returning-Result arithmetic path for user-driven expressions instead of the panicking Neg operator.","Constrain input decimals so values cannot reach i256::MIN in expressions that negate."],"exampleFix":"// before\nlet y = -x;\n// after\nlet y = if x == i256::MIN { return Err(ErrorCode::Overflow(\"decimal negation\")); } else { -x };","handlingStrategy":"validation","validationCode":"if x == i256::MIN {\n    return Err(ErrorCode::Overflow(\"negating i256::MIN overflows\"));\n}\nlet y = -x;","typeGuard":"fn negatable(x: i256) -> bool { x != i256::MIN }","tryCatchPattern":null,"preventionTips":["Use checked arithmetic paths for user-driven decimal expressions.","Test decimal edge cases (i256::MIN/MAX) in arithmetic operator unit tests."],"tags":["panic","overflow","decimal","arithmetic"],"backgroundTag":"value-out-of-range","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}