From 84d0b4fcfb74288a8ed22f7786db8368a9a0a807 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 27 Dec 2017 18:38:42 +0000 Subject: ofz#4806 Infinite loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I89a24fa3ce4034ef207233b96c5e26a7b7787444 Reviewed-on: https://gerrit.libreoffice.org/47096 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- package/source/zipapi/ZipFile.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'package') diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 61f7ea1dacc1..de4c1a364acd 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -539,6 +539,7 @@ public: const sal_Int32 nBufSize = 8192; sal_Int32 nRemaining = xSrcStream->available(); + sal_Int32 nRead = 0; maBytes.reserve(nRemaining); uno::Sequence aBuf(nBufSize); @@ -552,10 +553,17 @@ public: }; while (nRemaining > nBufSize) - nRemaining -= readAndCopy(nBufSize); + { + const auto nBytes = readAndCopy(nBufSize); + if (!nBytes) + break; + nRead += nBytes; + nRemaining -= nBytes; + } if (nRemaining) - readAndCopy(nRemaining); + nRead += readAndCopy(nRemaining); + maBytes.resize(nRead); } virtual sal_Int32 SAL_CALL readBytes( uno::Sequence& rData, sal_Int32 nBytesToRead ) override -- cgit