From aa809b35b487b594166d7aa7ecccf221ac1054e1 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Fri, 7 Jun 2019 10:55:24 +0200 Subject: bail out immediately if saving part of a zip package fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's no point in continuing to write other parts if the final result will be a failure anyway. Moreover this avoids an assert in ZipOutputStream::writeLOC() if writing of the previous part resulted in an error (e.g. ZipException because of broken zip CRC for the stream) that skipped calling ZipOutputStream::rawCloseEntry(). Change-Id: I5095b97a31cac9befcab5e82bd8cda2dfa53c7f7 Reviewed-on: https://gerrit.libreoffice.org/73646 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- package/source/zippackage/ZipPackageFolder.cxx | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'package') diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 1aaaedcd3d89..bd7512a19fc8 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -287,8 +287,6 @@ void ZipPackageFolder::saveContents( sal_Int32 nPBKDF2IterationCount, const rtlRandomPool &rRandomPool ) const { - bool bWritingFailed = false; - if ( maContents.empty() && !rPath.isEmpty() && m_nFormat != embed::StorageFormats::OFOPXML ) { // it is an empty subfolder, use workaround to store it @@ -305,11 +303,11 @@ void ZipPackageFolder::saveContents( } catch ( ZipException& ) { - bWritingFailed = true; + throw uno::RuntimeException( THROW_WHERE ); } catch ( IOException& ) { - bWritingFailed = true; + throw uno::RuntimeException( THROW_WHERE ); } } @@ -322,8 +320,11 @@ void ZipPackageFolder::saveContents( if ( aIter != maContents.end() && !(*aIter).second->bFolder ) { bMimeTypeStreamStored = true; - bWritingFailed = !aIter->second->pStream->saveChild( - rPath + aIter->first, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ); + if( !aIter->second->pStream->saveChild( + rPath + aIter->first, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool )) + { + throw uno::RuntimeException( THROW_WHERE ); + } } } @@ -335,19 +336,22 @@ void ZipPackageFolder::saveContents( { if (rInfo.bFolder) { - bWritingFailed = !rInfo.pFolder->saveChild( - rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ); + if( !rInfo.pFolder->saveChild( + rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool )) + { + throw uno::RuntimeException( THROW_WHERE ); + } } else { - bWritingFailed = !rInfo.pStream->saveChild( - rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ); + if( !rInfo.pStream->saveChild( + rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool )) + { + throw uno::RuntimeException( THROW_WHERE ); + } } } } - - if( bWritingFailed ) - throw uno::RuntimeException(THROW_WHERE ); } sal_Int64 SAL_CALL ZipPackageFolder::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) -- cgit