From fb6b36b02842a2190276cbea848bcb5c92774d3a Mon Sep 17 00:00:00 2001 From: AlexPeshkoff Date: Fri, 26 Jun 2020 10:11:08 +0300 Subject: [PATCH] Backported CORE-6345: Server crashes on overflow of division result --- src/dsql/ExprNodes.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index b5d9470a14..387ce68f48 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -2003,10 +2003,6 @@ dsc* ArithmeticNode::divide2(const dsc* desc, impure_value* value) const SINT64 i1 = MOV_get_int64(&value->vlu_desc, nodScale - desc->dsc_scale); - // MIN_SINT64 / -1 = (MAX_SINT64 + 1), which overflows in SINT64. - if ((i1 == MIN_SINT64) && (i2 == -1)) - ERR_post(Arg::Gds(isc_exception_integer_overflow)); - // Scale the dividend by as many of the needed powers of 10 as possible // without causing an overflow. int addl_scale = 2 * desc->dsc_scale; @@ -2036,6 +2032,10 @@ dsc* ArithmeticNode::divide2(const dsc* desc, impure_value* value) const ++addl_scale; } + // MIN_SINT64 / -1 = (MAX_SINT64 + 1), which overflows in SINT64. + if ((i1 == MIN_SINT64) && (i2 == -1)) + ERR_post(Arg::Gds(isc_exception_integer_overflow)); + value->vlu_desc.dsc_dtype = dtype_int64; value->vlu_desc.dsc_length = sizeof(SINT64); value->vlu_desc.dsc_scale = nodScale;