[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - connectivity/source

Lionel Elie Mamane lionel at mamane.lu
Tue Aug 8 13:28:08 UTC 2017


 connectivity/source/commontools/dbconversion.cxx |   32 ++++++++++++++++++++---
 1 file changed, 28 insertions(+), 4 deletions(-)

New commits:
commit de8c0152157bb32a6df9b6d4ac4102aef8e8a384
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Wed Aug 2 15:27:57 2017 +0200

    tdf#110997 protect calls to implBuildFromRelative from year overflow
    
    Change-Id: I5c6768766673832b7271292af85db1b76e51042c
    Reviewed-on: https://gerrit.libreoffice.org/40683
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx
index 5be258a7e698..9baca9bebb80 100644
--- a/connectivity/source/commontools/dbconversion.cxx
+++ b/connectivity/source/commontools/dbconversion.cxx
@@ -42,6 +42,16 @@ namespace
     const sal_Int64 hourMask = 10000000000000LL;
 
     const double fNanoSecondsPerDay = nanoSecInSec * secInMin * minInHour * 24.0;
+
+    //  32767-12-31 in "(days since 0001-01-01) + 1" format
+    const sal_Int32 maxDays =  11967896;
+    // -32768-01-01 in "(days since 0001-01-01) + 1" format
+    // Yes, I know it is currently unused. Will have to be used
+    // when we implement negative years. Writing down the correct
+    // value for future reference.
+    // *** Please don't remove just because it is unused ***
+    // Lionel Élie Mamane 2017-08-02
+    // const sal_Int32 minDays = -11968270;
 }
 
 
@@ -269,8 +279,15 @@ namespace dbtools
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
         nTempDays += nDays;
-        // TODO: can we remove that check? Would allow dates before 1900.
-        if ( nTempDays <= 0 )
+        if ( nTempDays > maxDays )
+        {
+            _rDate.Day      = 31;
+            _rDate.Month    = 12;
+            _rDate.Year     = 9999;
+        }
+        // TODO: can we replace that check by minDays? Would allow dates BCE
+        //       implBuildFromRelative probably needs to be updated for the "no year 0" question
+        else if ( nTempDays <= 0 )
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;
@@ -285,8 +302,15 @@ namespace dbtools
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
         nTempDays -= nDays;
-        // TODO: can we remove that check? Would allow dates before 1900.
-        if ( nTempDays <= 0 )
+        if ( nTempDays > maxDays )
+        {
+            _rDate.Day      = 31;
+            _rDate.Month    = 12;
+            _rDate.Year     = 9999;
+        }
+        // TODO: can we replace that check by minDays? Would allow dates BCE
+        //       implBuildFromRelative probably needs to be updated for the "no year 0" question
+        else if ( nTempDays <= 0 )
         {
             _rDate.Day      = 1;
             _rDate.Month    = 1;


More information about the Libreoffice-commits mailing list