diff options
author | Eike Rathke <erack@redhat.com> | 2021-08-11 20:03:36 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-08-11 22:20:57 +0200 |
commit | b37fd7f38165dadc5b1a674b73f4b18824e4789e (patch) | |
tree | 9d32e77789ecb7a909b2c61d4444ac1b6dd4af53 | |
parent | 2316e21b2c6f3d1f18613408a8deb41af17c03bb (diff) |
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 <erack@redhat.com>
Tested-by: Jenkins
-rw-r--r-- | sc/inc/compiler.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 37 |
2 files changed, 31 insertions, 7 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index 8ae65a4eb8b3..be4c4cadcb1a 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -363,6 +363,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 d6ae770e5c91..434bd157bd4c 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3126,7 +3126,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; } @@ -3544,13 +3561,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); @@ -3560,9 +3575,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()); @@ -3573,7 +3596,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); |