Kaydet (Commit) 4d1cb2dc authored tarafından Matúš Kukan's avatar Matúš Kukan

package: Zipping STORED entry is the same as rawWrite and we don't encrypt it

Change-Id: Ie3f8ac261a70c9a2b5182fc7d36938d0a46ec045
üst 2d92a84a
......@@ -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);
}
}
......
......@@ -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 )
......
......@@ -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& )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment