scaddins/source/analysis/analysishelper.cxx |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

New commits:
commit ba56d1f0c9ece5df2f17e7166b4ee89155e54c43
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Feb 17 11:14:26 2026 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Fri Feb 20 09:54:16 2026 +0100

    tdf#170298 handle out of range value in EDATE function
    
    otherwise the code will get stuck in an infinite loop
    
    Change-Id: I5715df3e462f7cbde24bd6237fbd58d4c685272f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199525
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    (cherry picked from commit 08f940a22d202bb5ddc7d6d9be8c05275160b5e9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199688
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit 16c5aa0d23f8834f7af9de3498188ef044416a35)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199784

diff --git a/scaddins/source/analysis/analysishelper.cxx 
b/scaddins/source/analysis/analysishelper.cxx
index 73673bd4e593..79fe0ec6c5fe 100644
--- a/scaddins/source/analysis/analysishelper.cxx
+++ b/scaddins/source/analysis/analysishelper.cxx
@@ -209,7 +209,6 @@ void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, 
sal_uInt16& rMonth, sal_uInt
 {
     if( nDays < 0 )
         throw lang::IllegalArgumentException();
-
     sal_Int32   nTempDays;
     sal_Int32   i = 0;
     bool        bCalc;
@@ -217,7 +216,10 @@ void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, 
sal_uInt16& rMonth, sal_uInt
     do
     {
         nTempDays = nDays;
-        rYear = static_cast<sal_uInt16>((nTempDays / 365) - i);
+        sal_Int32 nTempYear = nTempDays / 365;
+        if (nTempYear > SAL_MAX_INT16)
+            throw lang::IllegalArgumentException("days value too large " + 
OUString::number(nDays), {}, 1);
+        rYear = static_cast<sal_uInt16>(nTempYear - i);
         nTempDays -= (static_cast<sal_Int32>(rYear) -1) * 365;
         nTempDays -= (( rYear -1) / 4) - (( rYear -1) / 100) + ((rYear -1) / 
400);
         bCalc = false;

Reply via email to