[Libreoffice-commits] core.git: 2 commits - dbaccess/source package/source sc/qa sc/source sfx2/source sw/source

Caolán McNamara caolanm at redhat.com
Wed Oct 2 03:43:32 PDT 2013


 dbaccess/source/ui/misc/UITools.cxx            |    2 -
 package/source/zippackage/ZipPackageStream.cxx |   34 +++++++++++++++++++++----
 sc/qa/unit/data/ods/passwordWrongSHA.ods       |binary
 sc/qa/unit/subsequent_filters-test.cxx         |   10 +++++++
 sc/source/core/tool/interpr1.cxx               |   12 ++++----
 sc/source/ui/inc/viewfunc.hxx                  |    2 -
 sc/source/ui/unoobj/funcuno.cxx                |    3 --
 sc/source/ui/view/viewfun2.cxx                 |    4 +-
 sfx2/source/bastyp/progress.cxx                |    2 -
 sfx2/source/doc/docfile.cxx                    |    2 -
 sw/source/filter/ww8/wrtww8.cxx                |   16 +++++------
 sw/source/filter/ww8/wrtww8.hxx                |   10 +++----
 12 files changed, 65 insertions(+), 32 deletions(-)

New commits:
commit 11ad93f4ba84f190c908e92a2c960f7a9fa800c0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Oct 2 11:38:22 2013 +0100

    Resolves: rhbz#1013844 fdo#47482 encrypted OOo 1.0 docs cannot be reopened
    
    Workaround for the encrypted OpenOffice.org 1.0 documents generated by
    Libreoffice <= 3.6 with the new encryption format and using SHA256, but missing
    a specified startkey of SHA256
    
    Change-Id: Ib1acc4441b5adc6721cb3cde7a1191aa978e9a1b

diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 78e647e..bb96203 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -535,13 +535,37 @@ uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
         {
             xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
         }
-        catch( packages::WrongPasswordException& )
+        catch( const packages::WrongPasswordException& )
         {
-            // workaround for the encrypted documents generated with the old OOo1.x bug.
-            if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
+            if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 )
             {
-                xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
-                m_bUseWinEncoding = true;
+                try
+                {
+                    // rhbz#1013844 / fdo#47482 workaround for the encrypted
+                    // OpenOffice.org 1.0 documents generated by Libreoffice <=
+                    // 3.6 with the new encryption format and using SHA256, but
+                    // missing a specified startkey of SHA256
+
+                    // force SHA256 and see if that works
+                    m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA256;
+                    xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+                    return xResult;
+                }
+                catch (const packages::WrongPasswordException&)
+                {
+                    // if that didn't work, restore to SHA1 and trundle through the *other* earlier
+                    // bug fix
+                    m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA1;
+                }
+
+                // workaround for the encrypted documents generated with the old OOo1.x bug.
+                if ( !m_bUseWinEncoding )
+                {
+                    xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
+                    m_bUseWinEncoding = true;
+                }
+                else
+                    throw;
             }
             else
                 throw;
diff --git a/sc/qa/unit/data/ods/passwordWrongSHA.ods b/sc/qa/unit/data/ods/passwordWrongSHA.ods
new file mode 100644
index 0000000..b8a0e80
Binary files /dev/null and b/sc/qa/unit/data/ods/passwordWrongSHA.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 7db8c16..34e9cd3 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -125,6 +125,7 @@ public:
     //misc tests unrelated to the import filters
     void testPasswordNew();
     void testPasswordOld();
+    void testPasswordWrongSHA();
 
     //test shape import
     void testControlImport();
@@ -198,6 +199,7 @@ public:
     //disable testPassword on MacOSX due to problems with libsqlite3
     //also crashes on DragonFly due to problems with nss/nspr headers
 #if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
+    CPPUNIT_TEST(testPasswordWrongSHA);
     CPPUNIT_TEST(testPasswordOld);
     CPPUNIT_TEST(testPasswordNew);
 #endif
@@ -1326,6 +1328,14 @@ void ScFiltersTest::testPasswordOld()
     testPassword_Impl(aFileNameBase);
 }
 
+void ScFiltersTest::testPasswordWrongSHA()
+{
+    //tests opening a file wrongly using the new password algorithm
+    //in a sxc with the key algorithm missing
+    const OUString aFileNameBase("passwordWrongSHA.");
+    testPassword_Impl(aFileNameBase);
+}
+
 void ScFiltersTest::testControlImport()
 {
     ScDocShellRef xDocSh = loadDoc("singlecontrol.", XLSX);
commit f7f421670206d265024a99da6bc1ad8781c30c99
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 1 20:12:42 2013 +0100

    remove some UniString::GetBuffer
    
    Change-Id: I808026a6f593b0251ee107d27e7ca12d55b2d0a0

diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx
index 4675cdc..d79aa47 100644
--- a/dbaccess/source/ui/misc/UITools.cxx
+++ b/dbaccess/source/ui/misc/UITools.cxx
@@ -616,7 +616,7 @@ void fillTypeInfo(  const Reference< ::com::sun::star::sdbc::XConnection>& _rxCo
             }
             if ( !aName.isEmpty() )
             {
-                pInfo->aUIName = aName.getStr();
+                pInfo->aUIName = aName;
                 pInfo->aUIName += aB1;
             }
             pInfo->aUIName += pInfo->aTypeName;
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index d3e0f96..54ce21d 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -3134,17 +3134,17 @@ void ScInterpreter::ScN()
 void ScInterpreter::ScTrim()
 {
     // Doesn't only trim but also removes duplicated blanks within!
-    String aVal = comphelper::string::strip(GetString(), ' ');
-    String aStr;
-    const sal_Unicode* p = aVal.GetBuffer();
-    const sal_Unicode* const pEnd = p + aVal.Len();
+    OUString aVal = comphelper::string::strip(GetString(), ' ');
+    OUStringBuffer aStr;
+    const sal_Unicode* p = aVal.getStr();
+    const sal_Unicode* const pEnd = p + aVal.getLength();
     while ( p < pEnd )
     {
         if ( *p != ' ' || p[-1] != ' ' )    // first can't be ' ', so -1 is fine
-            aStr += *p;
+            aStr.append(*p);
         p++;
     }
-    PushString( aStr );
+    PushString(aStr.makeStringAndClear());
 }
 
 
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 93e04e7..0ad6dbd 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -281,7 +281,7 @@ public:
     void            ExtendScenario();
     void            UseScenario( const String& rName );
 
-    void            InsertSpecialChar( const String& rStr, const Font& rFont );
+    void            InsertSpecialChar( const OUString& rStr, const Font& rFont );
 
     void            InsertDummyObject();
     void            InsertOleObject();
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index de55b28..1fd2840 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -569,8 +569,7 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const OUString& aName,
         {
             OUString aUStr;
             rArg >>= aUStr;
-            String aStr( aUStr );
-            aTokenArr.AddString( aStr.GetBuffer() );
+            aTokenArr.AddString( aUStr );
         }
         else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence<sal_Int16> > *)0 ) ) )
         {
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 2679692..6cb7c81 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2915,7 +2915,7 @@ void ScViewFunc::HideTable( const ScMarkData& rMark )
 
 //----------------------------------------------------------------------------
 
-void ScViewFunc::InsertSpecialChar( const String& rStr, const Font& rFont )
+void ScViewFunc::InsertSpecialChar( const OUString& rStr, const Font& rFont )
 {
     ScEditableTester aTester( this );
     if (!aTester.IsEditable())
@@ -2924,7 +2924,7 @@ void ScViewFunc::InsertSpecialChar( const String& rStr, const Font& rFont )
         return;
     }
 
-    const sal_Unicode* pChar    = rStr.GetBuffer();
+    const sal_Unicode* pChar    = rStr.getStr();
     ScTabViewShell* pViewShell  = GetViewData()->GetViewShell();
     SvxFontItem     aFontItem( rFont.GetFamily(),
                                rFont.GetName(),
diff --git a/sfx2/source/bastyp/progress.cxx b/sfx2/source/bastyp/progress.cxx
index d3a2569..06661d9 100644
--- a/sfx2/source/bastyp/progress.cxx
+++ b/sfx2/source/bastyp/progress.cxx
@@ -149,7 +149,7 @@ SfxProgress::SfxProgress
     pImp->nCreate = Get10ThSec();
     pImp->nNextReschedule = pImp->nCreate;
     DBG( DbgOutf( "SfxProgress: created for '%s' at %luds",
-                  rText.GetBuffer(), pImp->nCreate ) );
+                  rText.getStr(), pImp->nCreate ) );
     pImp->bAllDocs = bAll;
     pImp->pWorkWin = 0;
     pImp->pView = 0;
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 49cb292..63bbb43 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -1049,7 +1049,7 @@ bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI )
 
                     OUString aPhysPath;
                     if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) )
-                        bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() );
+                        bContentReadonly = IsReadonlyAccordingACL( aPhysPath.getStr() );
                 }
 #endif
 
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index e0029d9..471964a 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -1649,14 +1649,14 @@ void SwWW8Writer::InsUInt32(ww::bytes &rO, sal_uInt32 n)
     rO.push_back(nL[3]);
 }
 
-void SwWW8Writer::InsAsString16(ww::bytes &rO, const String& rStr)
+void SwWW8Writer::InsAsString16(ww::bytes &rO, const OUString& rStr)
 {
-    const sal_Unicode* pStr = rStr.GetBuffer();
-    for( xub_StrLen n = 0, nLen = rStr.Len(); n < nLen; ++n, ++pStr )
+    const sal_Unicode* pStr = rStr.getStr();
+    for (sal_Int32 n = 0, nLen = rStr.getLength(); n < nLen; ++n, ++pStr)
         SwWW8Writer::InsUInt16( rO, *pStr );
 }
 
-void SwWW8Writer::InsAsString8(ww::bytes &rO, const String& rStr,
+void SwWW8Writer::InsAsString8(ww::bytes &rO, const OUString& rStr,
         rtl_TextEncoding eCodeSet)
 {
     OString sTmp(OUStringToOString(rStr, eCodeSet));
@@ -1667,7 +1667,7 @@ void SwWW8Writer::InsAsString8(ww::bytes &rO, const String& rStr,
     std::copy(pStart, pEnd, std::inserter(rO, rO.end()));
 }
 
-void SwWW8Writer::WriteString16(SvStream& rStrm, const String& rStr,
+void SwWW8Writer::WriteString16(SvStream& rStrm, const OUString& rStr,
     bool bAddZero)
 {
     ww::bytes aBytes;
@@ -1680,10 +1680,10 @@ void SwWW8Writer::WriteString16(SvStream& rStrm, const String& rStr,
         rStrm.Write(&aBytes[0], aBytes.size());
 }
 
-void SwWW8Writer::WriteString_xstz(SvStream& rStrm, const String& rStr, bool bAddZero)
+void SwWW8Writer::WriteString_xstz(SvStream& rStrm, const OUString& rStr, bool bAddZero)
 {
     ww::bytes aBytes;
-    SwWW8Writer::InsUInt16(aBytes, rStr.Len());
+    SwWW8Writer::InsUInt16(aBytes, rStr.getLength());
     SwWW8Writer::InsAsString16(aBytes, rStr);
     if (bAddZero)
         SwWW8Writer::InsUInt16(aBytes, 0);
@@ -1691,7 +1691,7 @@ void SwWW8Writer::WriteString_xstz(SvStream& rStrm, const String& rStr, bool bAd
 }
 
 
-void SwWW8Writer::WriteString8(SvStream& rStrm, const String& rStr,
+void SwWW8Writer::WriteString8(SvStream& rStrm, const OUString& rStr,
     bool bAddZero, rtl_TextEncoding eCodeSet)
 {
     ww::bytes aBytes;
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 8d45349..b7f4c5c 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -871,8 +871,8 @@ public:
 public:
     static void InsUInt16(ww::bytes &rO, sal_uInt16 n);
     static void InsUInt32(ww::bytes &rO, sal_uInt32 n);
-    static void InsAsString16(ww::bytes &rO, const String& rStr);
-    static void InsAsString8(ww::bytes & O, const String& rStr,
+    static void InsAsString16(ww::bytes &rO, const OUString& rStr);
+    static void InsAsString8(ww::bytes & O, const OUString& rStr,
         rtl_TextEncoding eCodeSet);
 
     static sal_uLong FillUntil( SvStream& rStrm, sal_uLong nEndPos = 0 );
@@ -884,12 +884,12 @@ public:
     static void WriteLong( SvStream& rStrm, sal_Int32 nVal ) { rStrm << nVal; }
     static void WriteLong( SvStream& rStrm, sal_uLong nPos, sal_Int32 nVal );
 
-    static void WriteString16(SvStream& rStrm, const String& rStr,
+    static void WriteString16(SvStream& rStrm, const OUString& rStr,
         bool bAddZero);
-    static void WriteString8(SvStream& rStrm, const String& rStr,
+    static void WriteString8(SvStream& rStrm, const OUString& rStr,
         bool bAddZero, rtl_TextEncoding eCodeSet);
 
-    static void WriteString_xstz(SvStream& rStrm, const String& rStr, bool bAddZero);
+    static void WriteString_xstz(SvStream& rStrm, const OUString& rStr, bool bAddZero);
 
     bool InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec );
 


More information about the Libreoffice-commits mailing list