diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-11-08 09:57:29 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-11-08 12:51:51 +0100 |
commit | 1f17927afee6c874348056db7724f9729504720f (patch) | |
tree | d03d760e54b74f95c27096dfbee12c85be2b115b /sfx2 | |
parent | 083360df1b33cb8538dd098dbaa498b2b62087ca (diff) |
ofz#4106 Integer-overflow
Change-Id: I91109f652bc032811ade350b77d30424b5764ad8
Reviewed-on: https://gerrit.libreoffice.org/44449
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/oleprops.cxx | 23 |
1 files 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 <comphelper/types.hxx> +#include <o3tl/safeint.hxx> #include <tools/debug.hxx> #include <tools/datetime.hxx> #include <rtl/tencinfo.h> @@ -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 ); } |