From 319ac1ac8f3c78653592556f8c25481c3ee78151 Mon Sep 17 00:00:00 2001 From: DrRobotto Date: Tue, 1 Sep 2026 14:54:03 +0200 Subject: [PATCH] cid#1700598 - Guard the element probe against empty arrays Change-Id: I7c887abae0aa4c830aac54ce3e9cee0d890757b9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210333 Reviewed-by: Andreas Heinisch Tested-by: Jenkins --- basic/qa/basic_coverage/test_split_method.bas | 14 ++++++++++++++ basic/source/classes/sbunoobj.cxx | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/basic/qa/basic_coverage/test_split_method.bas b/basic/qa/basic_coverage/test_split_method.bas index 570308a85230..adf74283fcb8 100644 --- a/basic/qa/basic_coverage/test_split_method.bas +++ b/basic/qa/basic_coverage/test_split_method.bas @@ -66,6 +66,20 @@ Sub verify_testSplit ' - Actual : Object variable not set TestUtil.AssertEqual(oObject.TypeClass, 20, "CoreReflection.getType() for oObject.TypeClass after Split() + Array()") + ' cid#1700598 - guard the element probe against empty arrays + Dim aEmpty() As Integer + ' Without the fix in place, this assignment would have failed with + ' "Inadmissible value or data type. Index out of defined range" + oObject = oReflection.GetType(aEmpty) + TestUtil.AssertEqual(oObject.Name, "[]short", "CoreReflection.getType() for an empty Integer array") + + ' cid#1700598 - the element probe must use the dimension and not the flat storage index + Dim aNegative(-5 To -1) As Integer + ' Without the fix in place, this assignment would have failed with + ' "Inadmissible value or data type. Index out of defined range" + oObject = oReflection.GetType(aNegative) + TestUtil.AssertEqual(oObject.Name, "[]short", "CoreReflection.getType() for an array with a negative lower bound") + ' tdf#141474 keyword names need to match that of VBA TestUtil.AssertEqual(Split(expression:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" ) Dim txt As String : txt = "Libre_Office_Star_Office" diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 0344f327b09d..36e6fe6beba9 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -884,10 +884,11 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal ) bool bNeedsInit = eElementTypeClass == TypeClass_VOID || eElementTypeClass == TypeClass_ANY; bool bInspectElements = bNeedsInit; - if (!bInspectElements) + // cid#1700598 - guard the element probe against empty arrays + if (!bInspectElements && nLower <= nUpper) { sal_Int32 nFirstIdx = nLower; - SbxVariableRef xFirstVar = pArray->Get(nFirstIdx); + SbxVariableRef xFirstVar = pArray->Get(&nFirstIdx); if (xFirstVar && !xFirstVar->IsFixed()) bInspectElements = true; } @@ -930,7 +931,8 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal ) // tdf#146873 - inspect elements when they are non-fixed bool bNeedsInit = eElementTypeClass == TypeClass_VOID || eElementTypeClass == TypeClass_ANY; bool bInspectElements = bNeedsInit; - if (!bInspectElements) + // cid#1700598 - guard the element probe against empty arrays + if (!bInspectElements && pArray->Count() > 0) { SbxVariableRef xFirstVar = pArray->SbxArray::Get(0); if (xFirstVar && !xFirstVar->IsFixed())