summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-07-04 21:41:17 +0200
committerTomaž Vajngerl <quikee@gmail.com>2018-07-06 18:27:17 +0200
commitce7fb7473bc72d8a672c4fdcd49474721c9a2784 (patch)
tree9a94cbb9167acb2dc98843ea31122ad0d8635690 /oox/source
parent96fb57611f8c9fa19a12c0fd9ed6e0c383962ac7 (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>
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/crypto/Standard2007Engine.cxx7
1 files changed, 5 insertions, 2 deletions
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;
}