scaddins/source/analysis/analysishelper.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
New commits: commit 08f940a22d202bb5ddc7d6d9be8c05275160b5e9 Author: Noel Grandin <[email protected]> AuthorDate: Tue Feb 17 11:14:26 2026 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Tue Feb 17 14:15:51 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]> diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index 7443dc2cc4ac..8a36d99a0f7e 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -210,7 +210,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; @@ -218,7 +217,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;
