[Libreoffice-commits] core.git: oox/qa oox/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Jul 6 16:27:51 UTC 2018


 oox/qa/unit/CryptoTest.cxx               |    4 ++--
 oox/source/crypto/Standard2007Engine.cxx |    7 +++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

New commits:
commit ce7fb7473bc72d8a672c4fdcd49474721c9a2784
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jul 4 21:41:17 2018 +0200

    oox: Standard2007Engine - take size into account when decrypting
    
    Change-Id: I3a28344d28136c9785a9476b490d296143abfacf
    Reviewed-on: https://gerrit.libreoffice.org/56973
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/oox/qa/unit/CryptoTest.cxx b/oox/qa/unit/CryptoTest.cxx
index c35fa2f7d9a0..0dead9dcec6e 100644
--- a/oox/qa/unit/CryptoTest.cxx
+++ b/oox/qa/unit/CryptoTest.cxx
@@ -115,7 +115,7 @@ void CryptoTest::testStandard2007()
 
     OString aTestString = OUStringToOString("1234567890ABCDEFG", RTL_TEXTENCODING_UTF8);
 
-    aUnencryptedInput.WriteOString(aTestString);
+    aUnencryptedInput.WriteBytes(aTestString.getStr(), aTestString.getLength() + 1);
     aUnencryptedInput.Seek(STREAM_SEEK_TO_BEGIN);
 
     {
@@ -156,7 +156,7 @@ void CryptoTest::testStandard2007()
         const sal_Char* pData = static_cast<const sal_Char*>(aUnencryptedOutput.GetData());
         sal_uInt64 nSize = aUnencryptedOutput.GetSize();
 
-        CPPUNIT_ASSERT_EQUAL(sal_uInt64(32), nSize);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt64(18), nSize);
 
         OString aString(pData);
 
diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx
index 6da188f514c5..d1d92269d96c 100644
--- a/oox/source/crypto/Standard2007Engine.cxx
+++ b/oox/source/crypto/Standard2007Engine.cxx
@@ -151,7 +151,7 @@ bool Standard2007Engine::generateEncryptionKey(const OUString& password)
 bool Standard2007Engine::decrypt(BinaryXInputStream& aInputStream,
                                  BinaryXOutputStream& aOutputStream)
 {
-    aInputStream.skip(4); // Document unencrypted size - 4 bytes
+    sal_uInt32 totalSize = aInputStream.readuInt32(); // Document unencrypted size - 4 bytes
     aInputStream.skip(4); // Reserved 4 Bytes
 
     std::vector<sal_uInt8> iv;
@@ -160,11 +160,14 @@ bool Standard2007Engine::decrypt(BinaryXInputStream& aInputStream,
     std::vector<sal_uInt8> outputBuffer(4096);
     sal_uInt32 inputLength;
     sal_uInt32 outputLength;
+    sal_uInt32 remaining = totalSize;
 
     while ((inputLength = aInputStream.readMemory(inputBuffer.data(), inputBuffer.size())) > 0)
     {
         outputLength = aDecryptor.update(outputBuffer, inputBuffer, inputLength);
-        aOutputStream.writeMemory(outputBuffer.data(), outputLength);
+        sal_uInt32 writeLength = std::min(outputLength, remaining);
+        aOutputStream.writeMemory(outputBuffer.data(), writeLength);
+        remaining -= outputLength;
     }
     return true;
 }


More information about the Libreoffice-commits mailing list