From a52de700a0092ac547f3cbdc3c14e77b6da37955 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 28 Sep 2021 09:28:03 +0100 Subject: ofz: Integer-overflow in lcl_CalDate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FWIW we have another similar implementation of this as Calendar_hijri::getGregorianDay Change-Id: I785f739d8f69ed0e596c27411cc8c7c58c631866 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122757 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- connectivity/source/drivers/dbase/DTable.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'connectivity') diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index 0ec699d6a7db..73a0d5db7df1 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -155,17 +155,17 @@ void lcl_CalDate(sal_Int32 _nJulianDate,sal_Int32 _nJulianTime,css::util::DateTi { if ( _nJulianDate ) { - sal_Int32 ka = _nJulianDate; + sal_Int64 ka = _nJulianDate; if ( _nJulianDate >= 2299161 ) { - sal_Int32 ialp = static_cast( (static_cast(_nJulianDate) - 1867216.25 ) / 36524.25 ); - ka = _nJulianDate + 1 + ialp - ( ialp >> 2 ); + sal_Int64 ialp = static_cast( (static_cast(_nJulianDate) - 1867216.25 ) / 36524.25 ); + ka = ka + 1 + ialp - ( ialp >> 2 ); } - sal_Int32 kb = ka + 1524; - sal_Int32 kc = static_cast( (static_cast(kb) - 122.1 ) / 365.25 ); - sal_Int32 kd = static_cast(static_cast(kc) * 365.25); - sal_Int32 ke = static_cast(static_cast( kb - kd ) / 30.6001 ); - _rDateTime.Day = static_cast(kb - kd - static_cast( static_cast(ke) * 30.6001 )); + sal_Int64 kb = ka + 1524; + sal_Int64 kc = static_cast((static_cast(kb) - 122.1) / 365.25); + sal_Int64 kd = static_cast(static_cast(kc) * 365.25); + sal_Int64 ke = static_cast(static_cast(kb - kd) / 30.6001); + _rDateTime.Day = static_cast(kb - kd - static_cast( static_cast(ke) * 30.6001 )); if ( ke > 13 ) _rDateTime.Month = static_cast(ke - 13); else -- cgit