sc/inc/compiler.hxx              |    1 +
 sc/source/core/tool/compiler.cxx |   37 ++++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

New commits:
commit 3dd3c1ed99a014cb98a7a68668b9426020094ec2
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Aug 11 20:03:36 2021 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Aug 12 17:17:04 2021 +0200

    Resolves: tdf#143809 "INF" may be a named expression or DB area name
    
    ... to not be caught by rtl::math::stringToDouble() handling
    XMLSchema-2 "INF" and "NaN" and set as error.
    
    Change-Id: I9bf7aad416a69d4c3c0d49d6c80168097040a3e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120337
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit b37fd7f38165dadc5b1a674b73f4b18824e4789e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120352
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 4eadf561eacf..48d5230bbc14 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -343,6 +343,7 @@ private:
     bool IsColRowName( const OUString& );
     bool IsBoolean( const OUString& );
     void AutoCorrectParsedSymbol();
+    const ScRangeData* GetRangeData( SCTAB& rSheet, const OUString& rUpperName 
) const;
 
     void AdjustSheetLocalNameRelReferences( SCTAB nDelta );
     void SetRelNameReference();
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 0d1dc9d52aa6..4ff62fc5862a 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3088,7 +3088,24 @@ bool ScCompiler::IsValue( const OUString& rSym )
             return false;
         }
         if (eStatus == rtl_math_ConversionStatus_OutOfRange)
+        {
+            // rtl::math::stringToDouble() recognizes XMLSchema-2 "INF" and
+            // "NaN" (case sensitive) that could be named expressions or DB
+            // areas as well.
+            // rSym is already upper so "NaN" is not possible here.
+            if (!std::isfinite(fVal) && rSym == "INF")
+            {
+                SCTAB nSheet = -1;
+                if (GetRangeData( nSheet, rSym))
+                    return false;
+                if 
(rDoc.GetDBCollection()->getNamedDBs().findByUpperName(rSym))
+                    return false;
+            }
+            /* TODO: is there a specific reason why we don't accept an infinity
+             * value that would raise an error in the interpreter, instead of
+             * setting the hard error at the token array already? */
             SetError( FormulaError::IllegalArgument );
+        }
         maRawToken.SetDouble( fVal );
         return true;
     }
@@ -3506,13 +3523,11 @@ bool ScCompiler::IsMacro( const OUString& rName )
 #endif
 }
 
-bool ScCompiler::IsNamedRange( const OUString& rUpperName )
+const ScRangeData* ScCompiler::GetRangeData( SCTAB& rSheet, const OUString& 
rUpperName ) const
 {
-    // IsNamedRange is called only from NextNewToken, with an upper-case string
-
     // try local names first
-    sal_Int16 nSheet = aPos.Tab();
-    ScRangeName* pRangeName = rDoc.GetRangeName(nSheet);
+    rSheet = aPos.Tab();
+    const ScRangeName* pRangeName = rDoc.GetRangeName(rSheet);
     const ScRangeData* pData = nullptr;
     if (pRangeName)
         pData = pRangeName->findByUpperName(rUpperName);
@@ -3522,9 +3537,17 @@ bool ScCompiler::IsNamedRange( const OUString& 
rUpperName )
         if (pRangeName)
             pData = pRangeName->findByUpperName(rUpperName);
         if (pData)
-            nSheet = -1;
+            rSheet = -1;
     }
+    return pData;
+}
+
+bool ScCompiler::IsNamedRange( const OUString& rUpperName )
+{
+    // IsNamedRange is called only from NextNewToken, with an upper-case string
 
+    SCTAB nSheet = -1;
+    const ScRangeData* pData = GetRangeData( nSheet, rUpperName);
     if (pData)
     {
         maRawToken.SetName( nSheet, pData->GetIndex());
@@ -3535,7 +3558,7 @@ bool ScCompiler::IsNamedRange( const OUString& rUpperName 
)
     if (mnCurrentSheetEndPos > 0 && mnCurrentSheetTab >= 0)
     {
         OUString aName( rUpperName.copy( mnCurrentSheetEndPos));
-        pRangeName = rDoc.GetRangeName( mnCurrentSheetTab);
+        const ScRangeName* pRangeName = rDoc.GetRangeName( mnCurrentSheetTab);
         if (pRangeName)
         {
             pData = pRangeName->findByUpperName(aName);

Reply via email to