Skip to content

Commit 3ac0971

Browse files
kiszkkou
authored andcommitted
ARROW-8924: [C++][Gandiva] Avoid potential int overflow in castDATE_date32()
This PR avoids the potential int overflow due to int32 multiplication in castDATE_date32(). In https://github.com/apache/arrow/blob/master/cpp/src/gandiva/precompiled/time.cc#L461, the following code performs the multiplication of two `int32`. The result is also `int32`. Then, the result is converted to `int64`. This code may cause overflow if the result is more than 32-bit. To avoid the overflow, this PR pre-casts the constant to `int64`. As a result, the multiplication will become `int64` * `int64`. ``` gdv_date64 castDATE_date32(gdv_date32 days) { return days * MILLIS_IN_DAY; } ``` This can fix the following failure: ``` The following tests FAILED: 67 - gandiva-date-time-test (Failed) ``` Closes apache#7260 from kiszk/ARROW-8924 Authored-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 4f3601f commit 3ac0971

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cpp/src/gandiva/precompiled/time.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ FORCE_INLINE
458458
gdv_date32 castDATE_int32(gdv_int32 in) { return in; }
459459

460460
FORCE_INLINE
461-
gdv_date64 castDATE_date32(gdv_date32 days) { return days * MILLIS_IN_DAY; }
461+
gdv_date64 castDATE_date32(gdv_date32 days) {
462+
return days * static_cast<gdv_date64>(MILLIS_IN_DAY);
463+
}
462464

463465
static int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
464466

0 commit comments

Comments
 (0)