diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-07-04 21:41:17 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-07-06 18:27:17 +0200 |
commit | ce7fb7473bc72d8a672c4fdcd49474721c9a2784 (patch) | |
tree | 9a94cbb9167acb2dc98843ea31122ad0d8635690 | |
parent | 96fb57611f8c9fa19a12c0fd9ed6e0c383962ac7 (diff) |
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@gmail.com>
-rw-r--r-- | oox/qa/unit/CryptoTest.cxx | 4 | ||||
-rw-r--r-- | oox/source/crypto/Standard2007Engine.cxx | 7 |
2 files changed, 7 insertions, 4 deletions
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; } |