summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-20 22:02:48 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-11-17 10:49:21 +0100
commit4d1cb2dc5f1cae97ea44bded3b68d57076e21731 (patch)
tree0f3756ffd2d5232498c679d182bad50bc443927e /package
parent2d92a84a6aac37e34d1699fdebe0270468b4f746 (diff)
package: Zipping STORED entry is the same as rawWrite and we don't encrypt it
Change-Id: Ie3f8ac261a70c9a2b5182fc7d36938d0a46ec045
Diffstat (limited to 'package')
-rw-r--r--package/source/zipapi/ZipOutputEntry.cxx94
-rw-r--r--package/source/zippackage/ZipPackage.cxx4
-rw-r--r--package/source/zippackage/ZipPackageStream.cxx31
3 files changed, 58 insertions, 71 deletions
diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx
index 4e2f6d45a25b..b73f0a2d4f75 100644
--- a/package/source/zipapi/ZipOutputEntry.cxx
+++ b/package/source/zipapi/ZipOutputEntry.cxx
@@ -51,6 +51,7 @@ ZipOutputEntry::ZipOutputEntry( const uno::Reference< uno::XComponentContext >&
, m_bEncryptCurrentEntry(bEncrypt)
, m_pCurrentStream(NULL)
{
+ assert(m_pCurrentEntry->nMethod == DEFLATED && "Use ZipPackageStream::rawWrite() for STORED entries");
if (m_bEncryptCurrentEntry)
{
m_xCipherContext = ZipFile::StaticGetCipher( rxContext, pStream->GetEncryptionData(), true );
@@ -69,49 +70,37 @@ void SAL_CALL ZipOutputEntry::closeEntry( )
ZipEntry *pEntry = m_pCurrentEntry;
if (pEntry)
{
- switch (pEntry->nMethod)
+ m_aDeflater.finish();
+ while (!m_aDeflater.finished())
+ doDeflate();
+ if ((pEntry->nFlag & 8) == 0)
{
- case DEFLATED:
- m_aDeflater.finish();
- while (!m_aDeflater.finished())
- doDeflate();
- if ((pEntry->nFlag & 8) == 0)
- {
- if (pEntry->nSize != m_aDeflater.getTotalIn())
- {
- OSL_FAIL("Invalid entry size");
- }
- if (pEntry->nCompressedSize != m_aDeflater.getTotalOut())
- {
- // Different compression strategies make the merit of this
- // test somewhat dubious
- pEntry->nCompressedSize = m_aDeflater.getTotalOut();
- }
- if (pEntry->nCrc != m_aCRC.getValue())
- {
- OSL_FAIL("Invalid entry CRC-32");
- }
- }
- else
- {
- if ( !m_bEncryptCurrentEntry )
- {
- pEntry->nSize = m_aDeflater.getTotalIn();
- pEntry->nCompressedSize = m_aDeflater.getTotalOut();
- }
- pEntry->nCrc = m_aCRC.getValue();
- }
- m_aDeflater.reset();
- m_aCRC.reset();
- break;
- case STORED:
- if (!((pEntry->nFlag & 8) == 0))
- OSL_FAIL( "Serious error, one of compressed size, size or CRC was -1 in a STORED stream");
- break;
- default:
- OSL_FAIL("Invalid compression method");
- break;
+ if (pEntry->nSize != m_aDeflater.getTotalIn())
+ {
+ OSL_FAIL("Invalid entry size");
+ }
+ if (pEntry->nCompressedSize != m_aDeflater.getTotalOut())
+ {
+ // Different compression strategies make the merit of this
+ // test somewhat dubious
+ pEntry->nCompressedSize = m_aDeflater.getTotalOut();
+ }
+ if (pEntry->nCrc != m_aCRC.getValue())
+ {
+ OSL_FAIL("Invalid entry CRC-32");
+ }
}
+ else
+ {
+ if ( !m_bEncryptCurrentEntry )
+ {
+ pEntry->nSize = m_aDeflater.getTotalIn();
+ pEntry->nCompressedSize = m_aDeflater.getTotalOut();
+ }
+ pEntry->nCrc = m_aCRC.getValue();
+ }
+ m_aDeflater.reset();
+ m_aCRC.reset();
if (m_bEncryptCurrentEntry)
{
@@ -137,24 +126,13 @@ void SAL_CALL ZipOutputEntry::closeEntry( )
void SAL_CALL ZipOutputEntry::write( const Sequence< sal_Int8 >& rBuffer, sal_Int32 nNewOffset, sal_Int32 nNewLength )
throw(IOException, RuntimeException)
{
- switch (m_pCurrentEntry->nMethod)
+ if (!m_aDeflater.finished())
{
- case DEFLATED:
- if (!m_aDeflater.finished())
- {
- m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
- while (!m_aDeflater.needsInput())
- doDeflate();
- if (!m_bEncryptCurrentEntry)
- m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
- }
- break;
- case STORED:
- {
- Sequence < sal_Int8 > aTmpBuffer ( rBuffer.getConstArray(), nNewLength );
- m_pZipOutputStream->getChucker().WriteBytes( aTmpBuffer );
- }
- break;
+ m_aDeflater.setInputSegment(rBuffer, nNewOffset, nNewLength);
+ while (!m_aDeflater.needsInput())
+ doDeflate();
+ if (!m_bEncryptCurrentEntry)
+ m_aCRC.updateSegment(rBuffer, nNewOffset, nNewLength);
}
}
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index a05320a48951..23a737e31264 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -998,9 +998,7 @@ void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
try
{
aZipOut.putNextEntry(*pEntry);
- ZipOutputEntry aZipEntry(m_xContext, &aZipOut, *pEntry, NULL);
- aZipEntry.write(aType, 0, nBufferLength);
- aZipEntry.closeEntry();
+ aZipOut.rawWrite(aType, 0, nBufferLength);
aZipOut.rawCloseEntry();
}
catch ( const ::com::sun::star::io::IOException & r )
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 7547e9cf0dc5..edc1c7aa1818 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -485,8 +485,8 @@ bool ZipPackageStream::saveChild(
pTempEntry->sPath = rPath;
pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
- bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.getLength() || m_bHaveOwnKey);
- bool bToBeCompressed = bToBeEncrypted ? sal_True : m_bToBeCompressed;
+ const bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.getLength() || m_bHaveOwnKey);
+ const bool bToBeCompressed = bToBeEncrypted ? sal_True : m_bToBeCompressed;
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
@@ -732,20 +732,31 @@ bool ZipPackageStream::saveChild(
try
{
rZipOut.putNextEntry(*pTempEntry, bToBeEncrypted);
- ZipOutputEntry aZipEntry(m_xContext, &rZipOut, *pTempEntry, this, bToBeEncrypted);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
-
sal_Int32 nLength;
uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
- do
+
+ if (pTempEntry->nMethod == STORED)
{
- nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
- aZipEntry.write(aSeq, 0, nLength);
+ do
+ {
+ nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
+ rZipOut.rawWrite(aSeq, 0, nLength);
+ }
+ while ( nLength == n_ConstBufferSize );
+ }
+ else
+ {
+ ZipOutputEntry aZipEntry(m_xContext, &rZipOut, *pTempEntry, this, bToBeEncrypted);
+ do
+ {
+ nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
+ aZipEntry.write(aSeq, 0, nLength);
+ }
+ while ( nLength == n_ConstBufferSize );
+ aZipEntry.closeEntry();
}
- while ( nLength == n_ConstBufferSize );
-
- aZipEntry.closeEntry();
rZipOut.rawCloseEntry();
}
catch ( ZipException& )