[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - basic/source sc/qa

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 16 12:06:44 UTC 2020


 basic/source/classes/image.cxx                            |   12 ++
 sc/qa/extras/macros-test.cxx                              |   63 +++++++++++++-
 sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods |binary
 sc/qa/extras/testdocuments/testTypePassword.ods           |binary
 4 files changed, 71 insertions(+), 4 deletions(-)

New commits:
commit c6d7efe327820744f03a0fd6d2e68f74e97e2914
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon Aug 17 11:38:54 2020 +0300
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Sep 16 14:06:08 2020 +0200

    tdf#135799: properly load arrays in user-defined types from image
    
    This requires to reset Fixed flag temporarily, as in SbiParser::DefType
    for non-image case.
    
    And save the dimensions of the arrays in the custom types correctly:
    the dimensions are numbered from 1, not from 0.
    
    The existing unit test (that happened to not test anything actually)
    was fixed.
    
    Change-Id: I48c6b6d5d735d9972a2c0dd40345d5db75f87f39
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100877
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Signed-off-by: Xisco Fauli <xiscofauli at libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102748

diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index e6e277647459..edee7686e061 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -269,7 +269,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
                     nCount = nMaxRecords;
                 }
 
-                // User defined types
+                // User defined types; ref.: SbiParser::DefType
                 for (sal_uInt16 i = 0; i < nCount; i++)
                 {
                     OUString aTypeName = r.ReadUniOrByteString(eCharSet);
@@ -324,7 +324,8 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
                             else
                             {
                                 // an array
-                                SbxDimArray* pArray = new SbxDimArray();
+                                SbxDimArray* pArray = new SbxDimArray(
+                                    static_cast<SbxDataType>(aMemberType & 0x0FFF));
 
                                 sal_Int16 isFixedSize;
                                 r.ReadInt16(isFixedSize);
@@ -341,7 +342,12 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
                                     pArray->unoAddDim32(lBound, uBound);
                                 }
 
+                                const SbxFlagBits nSavFlags = pTypeElem->GetFlags();
+                                // need to reset the FIXED flag
+                                // when calling PutObject ( because the type will not match Object )
+                                pTypeElem->ResetFlag(SbxFlagBits::Fixed);
                                 pTypeElem->PutObject( pArray );
+                                pTypeElem->SetFlags(nSavFlags);
                             }
                         }
 
@@ -542,7 +548,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
                             sal_Int32 nDims = pArray->GetDims32();
                             r.WriteInt32(nDims);
 
-                            for (sal_Int32 d = 0; d < nDims; d++)
+                            for (sal_Int32 d = 1; d <= nDims; d++)
                             {
                                 sal_Int32 lBound;
                                 sal_Int32 uBound;
diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index 3801a9998895..05c3fc3dab40 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -37,6 +37,7 @@ public:
     void testPasswordProtectedStarBasic();
     void testRowColumn();
     void testPasswordProtectedUnicodeString();
+    void testPasswordProtectedArrayInUserType();
     void testTdf131296_legacy();
     void testTdf131296_new();
 
@@ -47,6 +48,7 @@ public:
     CPPUNIT_TEST(testPasswordProtectedStarBasic);
     CPPUNIT_TEST(testRowColumn);
     CPPUNIT_TEST(testPasswordProtectedUnicodeString);
+    CPPUNIT_TEST(testPasswordProtectedArrayInUserType);
     CPPUNIT_TEST(testTdf131296_legacy);
     CPPUNIT_TEST(testTdf131296_new);
 
@@ -132,7 +134,7 @@ void ScMacrosTest::testPasswordProtectedStarBasic()
 
     SfxObjectShell::CallXScript(
         xComponent,
-        "vnd.sun.Star.script:MyLibrary.Module1.Main?language=Basic&location=document",
+        "vnd.sun.Star.script:Standard.Module1.LoadAndExecuteTest?language=Basic&location=document",
         aParams, aRet, aOutParamIndex, aOutParam);
 
     OUString aValue = rDoc.GetString(0,0,0);
@@ -457,6 +459,65 @@ void ScMacrosTest::testPasswordProtectedUnicodeString()
     xCloseable->close(true);
 }
 
+void ScMacrosTest::testPasswordProtectedArrayInUserType()
+{
+    const OUString sMacroURL(
+        "vnd.sun.Star.script:Protected.Module1.TestMyType?language=Basic&location=document");
+    const OUString sLibName("Protected");
+
+    OUString aFileName;
+    createFileURL("ProtectedArrayInCustomType.ods", aFileName);
+    auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
+    CPPUNIT_ASSERT(xComponent);
+
+    // Check that loading password-protected macro image correctly loads array bounds
+    {
+        Any aRet;
+        Sequence<sal_Int16> aOutParamIndex;
+        Sequence<Any> aOutParam;
+        Sequence<uno::Any> aParams;
+
+        SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex,
+            aOutParam);
+
+        sal_Int16 nReturnValue;
+        aRet >>= nReturnValue;
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue);
+    }
+
+    // Unlock and load the library, to regenerate the image on save
+    css::uno::Reference<css::document::XEmbeddedScripts> xES(xComponent, UNO_QUERY_THROW);
+    css::uno::Reference<css::script::XLibraryContainer> xLC(xES->getBasicLibraries(),
+        UNO_QUERY_THROW);
+    css::uno::Reference<css::script::XLibraryContainerPassword> xPasswd(xLC, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xPasswd->isLibraryPasswordProtected(sLibName));
+    CPPUNIT_ASSERT(!xPasswd->isLibraryPasswordVerified(sLibName));
+    CPPUNIT_ASSERT(xPasswd->verifyLibraryPassword(sLibName, "password"));
+    xLC->loadLibrary(sLibName);
+    CPPUNIT_ASSERT(xLC->isLibraryLoaded(sLibName));
+
+    // Now check that saving stores array bounds correctly
+    saveAndReload(xComponent, "calc8");
+    CPPUNIT_ASSERT(xComponent);
+
+    {
+        Any aRet;
+        Sequence<sal_Int16> aOutParamIndex;
+        Sequence<Any> aOutParam;
+        Sequence<uno::Any> aParams;
+
+        SfxObjectShell::CallXScript(xComponent, sMacroURL, aParams, aRet, aOutParamIndex,
+            aOutParam);
+
+        sal_Int16 nReturnValue;
+        aRet >>= nReturnValue;
+        CPPUNIT_ASSERT_EQUAL(sal_Int16(1), nReturnValue);
+    }
+
+    css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW);
+    xCloseable->close(true);
+}
+
 void ScMacrosTest::testTdf131296_legacy()
 {
     // For legacy password-protected library images, we must correctly get the constants' values,
diff --git a/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods
new file mode 100644
index 000000000000..5d7b1a4c2791
Binary files /dev/null and b/sc/qa/extras/testdocuments/ProtectedArrayInCustomType.ods differ
diff --git a/sc/qa/extras/testdocuments/testTypePassword.ods b/sc/qa/extras/testdocuments/testTypePassword.ods
index 7f249bc95a6e..d75c17ace5b8 100644
Binary files a/sc/qa/extras/testdocuments/testTypePassword.ods and b/sc/qa/extras/testdocuments/testTypePassword.ods differ


More information about the Libreoffice-commits mailing list