diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-06-07 10:55:24 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-06-10 11:16:13 +0200 |
commit | aa809b35b487b594166d7aa7ecccf221ac1054e1 (patch) | |
tree | c9a9b2056c67d64e65b3488083eb046494520184 /package | |
parent | 01813e6e86709c929f5e545ba206224f0bb25e5f (diff) |
bail out immediately if saving part of a zip package fails
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 <l.lunak@collabora.com>
Diffstat (limited to 'package')
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 30 |
1 files changed, 17 insertions, 13 deletions
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 ) |