From 1f17927afee6c874348056db7724f9729504720f Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 8 Nov 2017 09:57:29 +0000 Subject: ofz#4106 Integer-overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I91109f652bc032811ade350b77d30424b5764ad8 Reviewed-on: https://gerrit.libreoffice.org/44449 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sfx2/source/doc/oleprops.cxx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx index f860d9b5be11..73af67e2a872 100644 --- a/sfx2/source/doc/oleprops.cxx +++ b/sfx2/source/doc/oleprops.cxx @@ -21,6 +21,7 @@ #include "oleprops.hxx" #include +#include #include #include #include @@ -561,19 +562,25 @@ void SfxOleDateProperty::ImplLoad( SvStream& rStrm ) double fValue(0.0); rStrm.ReadDouble( fValue ); //stored as number of days (not seconds) since December 31, 1899 - ::Date aDate(31, 12, 1899); - long nDays = fValue; - aDate.AddDays( nDays ); - maDate.Day = aDate.GetDay(); - maDate.Month = aDate.GetMonth(); - maDate.Year = aDate.GetYear(); + sal_Int32 nDays = fValue; + sal_Int32 nStartDays = ::Date::DateToDays(31, 12, 1899); + if (o3tl::checked_add(nStartDays, nDays, nStartDays)) + SAL_WARN("sfx.doc", "SfxOleDateProperty::ImplLoad bad date, ignored"); + else + { + ::Date aDate(31, 12, 1899); + aDate.AddDays(nDays); + maDate.Day = aDate.GetDay(); + maDate.Month = aDate.GetMonth(); + maDate.Year = aDate.GetYear(); + } } void SfxOleDateProperty::ImplSave( SvStream& rStrm ) { - long nDays = ::Date::DateToDays(maDate.Day, maDate.Month, maDate.Year); + sal_Int32 nDays = ::Date::DateToDays(maDate.Day, maDate.Month, maDate.Year); //number of days (not seconds) since December 31, 1899 - long nStartDays = ::Date::DateToDays(31, 12, 1899); + sal_Int32 nStartDays = ::Date::DateToDays(31, 12, 1899); double fValue = nDays-nStartDays; rStrm.WriteDouble( fValue ); } -- cgit