2000-11-13 12:38:03 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
2008-04-10 15:47:50 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-11-13 12:38:03 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 16:28:16 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_package.hxx"
|
2001-04-19 13:13:40 +00:00
|
|
|
#include <ZipFile.hxx>
|
|
|
|
#include <ZipEnumeration.hxx>
|
2001-07-04 13:56:37 +00:00
|
|
|
#include <com/sun/star/packages/zip/ZipConstants.hpp>
|
|
|
|
#include <rtl/cipher.h>
|
|
|
|
#include <rtl/digest.h>
|
2002-01-29 14:27:45 +00:00
|
|
|
/*
|
2001-07-04 13:56:37 +00:00
|
|
|
#include <XMemoryStream.hxx>
|
|
|
|
#include <XFileStream.hxx>
|
2002-01-29 14:27:45 +00:00
|
|
|
*/
|
|
|
|
#include <XUnbufferedStream.hxx>
|
2001-07-04 13:56:37 +00:00
|
|
|
#include <PackageConstants.hxx>
|
2001-11-15 19:22:18 +00:00
|
|
|
#include <EncryptedDataHeader.hxx>
|
2001-09-05 17:50:48 +00:00
|
|
|
#include <EncryptionData.hxx>
|
2001-09-14 14:03:35 +00:00
|
|
|
#include <MemoryByteGrabber.hxx>
|
2001-11-15 19:22:18 +00:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2003-03-26 13:16:07 +00:00
|
|
|
#include <com/sun/star/ucb/XProgressHandler.hpp>
|
|
|
|
|
|
|
|
#ifndef _CRC32_HXX_
|
|
|
|
#include <CRC32.hxx>
|
|
|
|
#endif
|
|
|
|
|
2001-07-12 16:54:22 +00:00
|
|
|
#include <string.h> // for memcpy
|
2001-04-19 13:13:40 +00:00
|
|
|
#include <vector>
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2009-02-12 10:27:21 +00:00
|
|
|
#include <comphelper/storagehelper.hxx>
|
|
|
|
|
2001-07-04 13:56:37 +00:00
|
|
|
using namespace vos;
|
2000-11-13 12:38:03 +00:00
|
|
|
using namespace rtl;
|
|
|
|
using namespace com::sun::star;
|
2001-07-04 13:56:37 +00:00
|
|
|
using namespace com::sun::star::io;
|
2001-04-27 13:56:07 +00:00
|
|
|
using namespace com::sun::star::uno;
|
2003-03-26 13:16:07 +00:00
|
|
|
using namespace com::sun::star::ucb;
|
2001-06-15 14:25:10 +00:00
|
|
|
using namespace com::sun::star::lang;
|
2001-04-27 13:56:07 +00:00
|
|
|
using namespace com::sun::star::packages;
|
2001-07-04 13:56:37 +00:00
|
|
|
using namespace com::sun::star::packages::zip;
|
|
|
|
using namespace com::sun::star::packages::zip::ZipConstants;
|
|
|
|
|
|
|
|
|
2001-09-05 17:50:48 +00:00
|
|
|
/** This class is used to read entries from a zip file
|
|
|
|
*/
|
2003-03-26 13:16:07 +00:00
|
|
|
ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise )
|
2001-09-05 17:50:48 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2006-06-20 05:13:42 +00:00
|
|
|
: aGrabber(xInput)
|
2001-09-05 17:50:48 +00:00
|
|
|
, aInflater (sal_True)
|
2006-06-20 05:13:42 +00:00
|
|
|
, xStream(xInput)
|
|
|
|
, xSeek(xInput, UNO_QUERY)
|
2001-09-05 17:50:48 +00:00
|
|
|
, xFactory ( xNewFactory )
|
2005-03-15 10:50:19 +00:00
|
|
|
, bRecoveryMode( sal_False )
|
2001-09-05 17:50:48 +00:00
|
|
|
{
|
|
|
|
if (bInitialise)
|
|
|
|
{
|
|
|
|
if ( readCEN() == -1 )
|
2002-09-25 09:28:31 +00:00
|
|
|
{
|
2001-09-05 17:50:48 +00:00
|
|
|
aEntries.clear();
|
2002-09-25 09:28:31 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () );
|
|
|
|
}
|
2001-09-05 17:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
ZipFile::ZipFile( Reference < XInputStream > &xInput, const Reference < XMultiServiceFactory > &xNewFactory, sal_Bool bInitialise, sal_Bool bForceRecovery, Reference < XProgressHandler > xProgress )
|
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2006-06-20 05:13:42 +00:00
|
|
|
: aGrabber(xInput)
|
2003-03-26 13:16:07 +00:00
|
|
|
, aInflater (sal_True)
|
2006-06-20 05:13:42 +00:00
|
|
|
, xStream(xInput)
|
|
|
|
, xSeek(xInput, UNO_QUERY)
|
2003-03-26 13:16:07 +00:00
|
|
|
, xFactory ( xNewFactory )
|
|
|
|
, xProgressHandler( xProgress )
|
2005-03-15 10:50:19 +00:00
|
|
|
, bRecoveryMode( bForceRecovery )
|
2003-03-26 13:16:07 +00:00
|
|
|
{
|
|
|
|
if (bInitialise)
|
|
|
|
{
|
|
|
|
if ( bForceRecovery )
|
|
|
|
{
|
|
|
|
recover();
|
|
|
|
}
|
|
|
|
else if ( readCEN() == -1 )
|
|
|
|
{
|
|
|
|
aEntries.clear();
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "stream data looks to be broken" ) ), Reference < XInterface > () );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-05 17:50:48 +00:00
|
|
|
ZipFile::~ZipFile()
|
|
|
|
{
|
|
|
|
aEntries.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZipFile::setInputStream ( Reference < XInputStream > xNewStream )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2001-09-05 17:50:48 +00:00
|
|
|
xStream = xNewStream;
|
|
|
|
xSeek = Reference < XSeekable > ( xStream, UNO_QUERY );
|
|
|
|
aGrabber.setInputStream ( xStream );
|
|
|
|
}
|
|
|
|
|
2009-06-03 11:26:39 +00:00
|
|
|
sal_Bool ZipFile::StaticGetCipher ( const ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode )
|
2001-07-04 13:56:37 +00:00
|
|
|
{
|
2009-06-03 11:26:39 +00:00
|
|
|
sal_Bool bResult = sal_False;
|
2001-11-15 19:22:18 +00:00
|
|
|
if ( ! xEncryptionData.isEmpty() )
|
|
|
|
{
|
|
|
|
Sequence < sal_uInt8 > aDerivedKey (16);
|
|
|
|
rtlCipherError aResult;
|
|
|
|
Sequence < sal_Int8 > aDecryptBuffer;
|
|
|
|
|
|
|
|
// Get the key
|
|
|
|
rtl_digest_PBKDF2 ( aDerivedKey.getArray(), 16,
|
|
|
|
reinterpret_cast < const sal_uInt8 * > (xEncryptionData->aKey.getConstArray() ),
|
|
|
|
xEncryptionData->aKey.getLength(),
|
|
|
|
reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aSalt.getConstArray() ),
|
|
|
|
xEncryptionData->aSalt.getLength(),
|
|
|
|
xEncryptionData->nIterationCount );
|
|
|
|
|
|
|
|
rCipher = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
|
2009-06-03 11:26:39 +00:00
|
|
|
aResult = rtl_cipher_init( rCipher, bDecode ? rtl_Cipher_DirectionDecode : rtl_Cipher_DirectionEncode,
|
2001-11-15 19:22:18 +00:00
|
|
|
aDerivedKey.getConstArray(),
|
|
|
|
aDerivedKey.getLength(),
|
|
|
|
reinterpret_cast < const sal_uInt8 * > ( xEncryptionData->aInitVector.getConstArray() ),
|
|
|
|
xEncryptionData->aInitVector.getLength());
|
|
|
|
OSL_ASSERT (aResult == rtl_Cipher_E_None);
|
2009-06-03 11:26:39 +00:00
|
|
|
|
|
|
|
bResult = ( aResult == rtl_Cipher_E_None );
|
2001-11-15 19:22:18 +00:00
|
|
|
}
|
2009-06-03 11:26:39 +00:00
|
|
|
|
|
|
|
return bResult;
|
2001-07-04 13:56:37 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
void ZipFile::StaticFillHeader ( const ORef < EncryptionData > & rData,
|
|
|
|
sal_Int32 nSize,
|
|
|
|
const ::rtl::OUString& aMediaType,
|
|
|
|
sal_Int8 * & pHeader )
|
2001-11-15 19:22:18 +00:00
|
|
|
{
|
|
|
|
// I think it's safe to restrict vector and salt length to 2 bytes !
|
|
|
|
sal_Int16 nIVLength = static_cast < sal_Int16 > ( rData->aInitVector.getLength() );
|
|
|
|
sal_Int16 nSaltLength = static_cast < sal_Int16 > ( rData->aSalt.getLength() );
|
|
|
|
sal_Int16 nDigestLength = static_cast < sal_Int16 > ( rData->aDigest.getLength() );
|
2003-09-11 09:17:20 +00:00
|
|
|
sal_Int16 nMediaTypeLength = static_cast < sal_Int16 > ( aMediaType.getLength() * sizeof( sal_Unicode ) );
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// First the header
|
|
|
|
*(pHeader++) = ( n_ConstHeader >> 0 ) & 0xFF;
|
|
|
|
*(pHeader++) = ( n_ConstHeader >> 8 ) & 0xFF;
|
|
|
|
*(pHeader++) = ( n_ConstHeader >> 16 ) & 0xFF;
|
|
|
|
*(pHeader++) = ( n_ConstHeader >> 24 ) & 0xFF;
|
|
|
|
|
|
|
|
// Then the version
|
|
|
|
*(pHeader++) = ( n_ConstCurrentVersion >> 0 ) & 0xFF;
|
|
|
|
*(pHeader++) = ( n_ConstCurrentVersion >> 8 ) & 0xFF;
|
|
|
|
|
|
|
|
// Then the iteration Count
|
|
|
|
sal_Int32 nIterationCount = rData->nIterationCount;
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 8 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 16 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIterationCount >> 24 ) & 0xFF);
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// Then the size
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 8 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 16 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSize >> 24 ) & 0xFF);
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// Then the salt length
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nSaltLength >> 8 ) & 0xFF);
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// Then the IV length
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nIVLength >> 8 ) & 0xFF);
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// Then the digest length
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nDigestLength >> 8 ) & 0xFF);
|
2001-11-15 19:22:18 +00:00
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
// Then the mediatype length
|
2006-06-20 05:13:42 +00:00
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 0 ) & 0xFF);
|
|
|
|
*(pHeader++) = static_cast< sal_Int8 >(( nMediaTypeLength >> 8 ) & 0xFF);
|
2003-09-11 09:17:20 +00:00
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
// Then the salt content
|
|
|
|
memcpy ( pHeader, rData->aSalt.getConstArray(), nSaltLength );
|
|
|
|
pHeader += nSaltLength;
|
|
|
|
|
|
|
|
// Then the IV content
|
|
|
|
memcpy ( pHeader, rData->aInitVector.getConstArray(), nIVLength );
|
|
|
|
pHeader += nIVLength;
|
|
|
|
|
|
|
|
// Then the digest content
|
|
|
|
memcpy ( pHeader, rData->aDigest.getConstArray(), nDigestLength );
|
|
|
|
pHeader += nDigestLength;
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
// Then the mediatype itself
|
|
|
|
memcpy ( pHeader, aMediaType.getStr(), nMediaTypeLength );
|
|
|
|
pHeader += nMediaTypeLength;
|
2001-11-15 19:22:18 +00:00
|
|
|
}
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
sal_Bool ZipFile::StaticFillData ( ORef < EncryptionData > & rData,
|
|
|
|
sal_Int32 &rSize,
|
|
|
|
::rtl::OUString& aMediaType,
|
|
|
|
Reference < XInputStream > &rStream )
|
2001-11-15 19:22:18 +00:00
|
|
|
{
|
|
|
|
sal_Bool bOk = sal_False;
|
|
|
|
const sal_Int32 nHeaderSize = n_ConstHeaderSize - 4;
|
|
|
|
Sequence < sal_Int8 > aBuffer ( nHeaderSize );
|
|
|
|
if ( nHeaderSize == rStream->readBytes ( aBuffer, nHeaderSize ) )
|
|
|
|
{
|
|
|
|
sal_Int16 nPos = 0;
|
|
|
|
sal_Int8 *pBuffer = aBuffer.getArray();
|
|
|
|
sal_Int16 nVersion = pBuffer[nPos++] & 0xFF;
|
|
|
|
nVersion |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
if ( nVersion == n_ConstCurrentVersion )
|
|
|
|
{
|
|
|
|
sal_Int32 nCount = pBuffer[nPos++] & 0xFF;
|
|
|
|
nCount |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
nCount |= ( pBuffer[nPos++] & 0xFF ) << 16;
|
|
|
|
nCount |= ( pBuffer[nPos++] & 0xFF ) << 24;
|
|
|
|
rData->nIterationCount = nCount;
|
|
|
|
|
|
|
|
rSize = pBuffer[nPos++] & 0xFF;
|
|
|
|
rSize |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
rSize |= ( pBuffer[nPos++] & 0xFF ) << 16;
|
|
|
|
rSize |= ( pBuffer[nPos++] & 0xFF ) << 24;
|
|
|
|
|
|
|
|
sal_Int16 nSaltLength = pBuffer[nPos++] & 0xFF;
|
|
|
|
nSaltLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
sal_Int16 nIVLength = ( pBuffer[nPos++] & 0xFF );
|
|
|
|
nIVLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
sal_Int16 nDigestLength = pBuffer[nPos++] & 0xFF;
|
|
|
|
nDigestLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
sal_Int16 nMediaTypeLength = pBuffer[nPos++] & 0xFF;
|
|
|
|
nMediaTypeLength |= ( pBuffer[nPos++] & 0xFF ) << 8;
|
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
if ( nSaltLength == rStream->readBytes ( aBuffer, nSaltLength ) )
|
|
|
|
{
|
|
|
|
rData->aSalt.realloc ( nSaltLength );
|
|
|
|
memcpy ( rData->aSalt.getArray(), aBuffer.getConstArray(), nSaltLength );
|
|
|
|
if ( nIVLength == rStream->readBytes ( aBuffer, nIVLength ) )
|
|
|
|
{
|
|
|
|
rData->aInitVector.realloc ( nIVLength );
|
|
|
|
memcpy ( rData->aInitVector.getArray(), aBuffer.getConstArray(), nIVLength );
|
|
|
|
if ( nDigestLength == rStream->readBytes ( aBuffer, nDigestLength ) )
|
|
|
|
{
|
|
|
|
rData->aDigest.realloc ( nDigestLength );
|
|
|
|
memcpy ( rData->aDigest.getArray(), aBuffer.getConstArray(), nDigestLength );
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
if ( nMediaTypeLength == rStream->readBytes ( aBuffer, nMediaTypeLength ) )
|
|
|
|
{
|
|
|
|
aMediaType = ::rtl::OUString( (sal_Unicode*)aBuffer.getConstArray(),
|
|
|
|
nMediaTypeLength / sizeof( sal_Unicode ) );
|
|
|
|
bOk = sal_True;
|
|
|
|
}
|
2001-11-15 19:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bOk;
|
|
|
|
}
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const Reference< XInputStream >& xStream,
|
|
|
|
const ORef < EncryptionData > &rData )
|
|
|
|
throw ( packages::WrongPasswordException, ZipIOException, RuntimeException )
|
|
|
|
{
|
|
|
|
if ( rData.isEmpty() )
|
|
|
|
throw ZipIOException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
|
|
|
|
if ( !rData->aKey.getLength() )
|
CWS-TOOLING: integrate CWS fwk103
2009-05-26 12:44:25 +0200 mst r272292 : #i100727#
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx:
+ fix warning: rename method to prevent overloading
2009-05-19 13:42:31 +0200 mav r272075 : #i101356# add comment
2009-05-19 10:56:24 +0200 mav r272062 : #i101356# register the singleton correctly
2009-05-19 10:25:42 +0200 mav r272060 : #i101356# register the singleton correctly
2009-05-18 12:48:48 +0200 mav r272013 : #i91306# fix the typo
2009-05-14 08:50:06 +0200 mav r271871 : #i101356# reduce the amount of macros
2009-05-13 13:26:08 +0200 mav r271858 : #i101356# reduce the amount of macros
2009-05-13 11:29:16 +0200 mav r271849 : #i101356# reduce the amount of macros
2009-05-12 12:09:42 +0200 mav r271815 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 12:03:20 +0200 mav r271814 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:58:48 +0200 mav r271813 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:53:05 +0200 mav r271812 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:48:36 +0200 mav r271810 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:43:45 +0200 mav r271809 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:39:38 +0200 mav r271808 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:37:38 +0200 mav r271806 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:33:58 +0200 mav r271805 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:30:01 +0200 mav r271804 : #i101356# allow to generate a small log if a document can not be stored
2009-05-06 17:43:38 +0200 mst r271607 : #i100727#
- svtools/source/svhtml/parhtml.cxx:
+ adapt code to renaming of HTML constants (sb107)
2009-05-05 11:14:18 +0200 mav r271507 : #i101222# avoid warning
2009-05-05 10:27:23 +0200 mav r271505 : #i101426# send the modified() notification only when the document can be modified
2009-05-05 10:25:07 +0200 mav r271504 : #i101426# send the modified() notification only when the document is modified
2009-05-05 08:42:48 +0200 mav r271497 : CWS-TOOLING: rebase CWS fwk103 to trunk@271427 (milestone: DEV300:m47)
2009-04-30 13:32:11 +0200 mav r271412 : #i100518# check the template folders quietly
2009-04-29 20:04:25 +0200 mst r271393 : - sw/source/filter/html/swhtml.cxx:
+ fix wrong initialization order in constructor
2009-04-28 12:28:46 +0200 mav r271319 : #i99142# set the error correctly
2009-04-28 08:44:48 +0200 mav r271305 : #i99050# clear hidden flag if necessary
2009-04-28 08:40:10 +0200 mav r271304 : #i99050# avoid crash
2009-04-22 07:40:11 +0200 mav r271056 : #i101093# lets not affect the performance
2009-04-15 09:30:47 +0200 cd r270820 : #i99771# Fix warnings for gcc 4.4
2009-04-15 09:19:52 +0200 cd r270819 : #i99771# Fix warnings for gcc 4.4
2009-04-15 08:42:34 +0200 cd r270817 : #i99771# Fix warnings for gcc 4.4
2009-04-14 14:31:01 +0200 mav r270768 : #i99493# fix typo
2009-04-01 12:45:43 +0200 mst r270317 : fix #i100727#
- svtools/inc/svtools/svparser.hxx, svtools/source/svrtf/svparser.cxx,
sfx2/inc/sfx2/docfile.hxx, sfx2/source/doc/{objmisc.cxx,docfile.cxx}:
+ move SvKeyValue stuff from sfx2 to svtools
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx,
sfx2/inc/sfx2/sfxhtml.hxx, sfx2/source/bastyp/sfxhtml.cxx:
+ move ParseMetaOptions() and GetEncodingByMIME() from SfxHTMLParser (sfx2)
to HTMLParser (svtools)
+ make HTMLParser::ParseMetaOptions() a virtual function
+ HTMLParser::ParseMetaOptions() calls GetExtendedCompatibilityTextEncoding()
+ new template method HTMLParser::AddMetaUserDefined()
- svtools/source/svhtml/makefile.mk:
+ enable exceptions for parhtml.cxx
- dbaccess/source/ui/misc/HtmlReader.cxx,
sc/source/filter/html/htmlpars.cxx:
+ remove encoding related code duplication
- sw/source/filter/html/{swhtml{.hxx,.cxx},htmlfld.cxx}:
+ new SwHTMLParser::AddMetaUserDefined() for import of
DOCINFO field subtypes INFO[1-4]
+ do not use DocumentInfo for import of DOCINFO field subtypes INFO[1-4]
2009-03-31 17:01:35 +0200 mav r270288 : #i91214# fix typo
2009-03-31 15:19:41 +0200 mav r270285 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 15:00:36 +0200 mav r270284 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 12:19:13 +0200 mav r270270 : #i100123# taking the lock file over throws no exception
2009-03-30 13:57:21 +0200 mav r270227 : #i100351# fix the typo
2009-03-30 13:47:26 +0200 mav r270225 : #i99885# let OK be default button
2009-03-29 19:38:55 +0200 mav r270190 : CWS-TOOLING: rebase CWS fwk103 to trunk@270033 (milestone: DEV300:m45)
2009-03-16 16:39:48 +0100 mav r269558 : #i93558# convert the attributes as well
2009-03-13 15:35:55 +0100 mav r269488 : #i93558# improve manifest.xml parsing
2009-03-13 08:47:00 +0100 mav r269454 : #i96205# allow to remove password on SaveAs
2009-03-12 13:36:07 +0100 mav r269398 : #i91306# show special error in case of shared document
2009-03-12 13:33:35 +0100 mav r269397 : #i91306# introduce the new error-message
2009-03-12 11:40:42 +0100 mst r269378 : fix #i90877#
- svtools/source/uno/unoevent.cxx:
+ use proper operator delete[]
2009-02-26 15:23:10 +0100 mav r268526 : #i91214# do not use ATL
2009-02-26 14:19:06 +0100 mav r268516 : #i98909# integrate the patch
2009-02-10 17:29:52 +0100 cd r267568 : #i98649# Make sure that we catch the NoSuchElementException when a module is not installed.
2009-06-16 16:15:54 +00:00
|
|
|
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
Reference< XSeekable > xSeek( xStream, UNO_QUERY );
|
|
|
|
if ( !xSeek.is() )
|
|
|
|
throw ZipIOException( OUString::createFromAscii( "The stream must be seekable!\n" ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
|
|
|
|
|
|
|
|
// if we have a digest, then this file is an encrypted one and we should
|
|
|
|
// check if we can decrypt it or not
|
|
|
|
OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" );
|
|
|
|
if ( rData->aDigest.getLength() )
|
|
|
|
{
|
2006-06-20 05:13:42 +00:00
|
|
|
sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() );
|
2003-09-11 09:17:20 +00:00
|
|
|
nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize;
|
|
|
|
|
|
|
|
// skip header
|
|
|
|
xSeek->seek( n_ConstHeaderSize + rData->aInitVector.getLength() +
|
|
|
|
rData->aSalt.getLength() + rData->aDigest.getLength() );
|
|
|
|
|
|
|
|
// Only want to read enough to verify the digest
|
|
|
|
Sequence < sal_Int8 > aReadBuffer ( nSize );
|
|
|
|
|
|
|
|
xStream->readBytes( aReadBuffer, nSize );
|
|
|
|
|
|
|
|
if ( !StaticHasValidPassword( aReadBuffer, rData ) )
|
CWS-TOOLING: integrate CWS fwk103
2009-05-26 12:44:25 +0200 mst r272292 : #i100727#
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx:
+ fix warning: rename method to prevent overloading
2009-05-19 13:42:31 +0200 mav r272075 : #i101356# add comment
2009-05-19 10:56:24 +0200 mav r272062 : #i101356# register the singleton correctly
2009-05-19 10:25:42 +0200 mav r272060 : #i101356# register the singleton correctly
2009-05-18 12:48:48 +0200 mav r272013 : #i91306# fix the typo
2009-05-14 08:50:06 +0200 mav r271871 : #i101356# reduce the amount of macros
2009-05-13 13:26:08 +0200 mav r271858 : #i101356# reduce the amount of macros
2009-05-13 11:29:16 +0200 mav r271849 : #i101356# reduce the amount of macros
2009-05-12 12:09:42 +0200 mav r271815 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 12:03:20 +0200 mav r271814 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:58:48 +0200 mav r271813 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:53:05 +0200 mav r271812 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:48:36 +0200 mav r271810 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:43:45 +0200 mav r271809 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:39:38 +0200 mav r271808 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:37:38 +0200 mav r271806 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:33:58 +0200 mav r271805 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:30:01 +0200 mav r271804 : #i101356# allow to generate a small log if a document can not be stored
2009-05-06 17:43:38 +0200 mst r271607 : #i100727#
- svtools/source/svhtml/parhtml.cxx:
+ adapt code to renaming of HTML constants (sb107)
2009-05-05 11:14:18 +0200 mav r271507 : #i101222# avoid warning
2009-05-05 10:27:23 +0200 mav r271505 : #i101426# send the modified() notification only when the document can be modified
2009-05-05 10:25:07 +0200 mav r271504 : #i101426# send the modified() notification only when the document is modified
2009-05-05 08:42:48 +0200 mav r271497 : CWS-TOOLING: rebase CWS fwk103 to trunk@271427 (milestone: DEV300:m47)
2009-04-30 13:32:11 +0200 mav r271412 : #i100518# check the template folders quietly
2009-04-29 20:04:25 +0200 mst r271393 : - sw/source/filter/html/swhtml.cxx:
+ fix wrong initialization order in constructor
2009-04-28 12:28:46 +0200 mav r271319 : #i99142# set the error correctly
2009-04-28 08:44:48 +0200 mav r271305 : #i99050# clear hidden flag if necessary
2009-04-28 08:40:10 +0200 mav r271304 : #i99050# avoid crash
2009-04-22 07:40:11 +0200 mav r271056 : #i101093# lets not affect the performance
2009-04-15 09:30:47 +0200 cd r270820 : #i99771# Fix warnings for gcc 4.4
2009-04-15 09:19:52 +0200 cd r270819 : #i99771# Fix warnings for gcc 4.4
2009-04-15 08:42:34 +0200 cd r270817 : #i99771# Fix warnings for gcc 4.4
2009-04-14 14:31:01 +0200 mav r270768 : #i99493# fix typo
2009-04-01 12:45:43 +0200 mst r270317 : fix #i100727#
- svtools/inc/svtools/svparser.hxx, svtools/source/svrtf/svparser.cxx,
sfx2/inc/sfx2/docfile.hxx, sfx2/source/doc/{objmisc.cxx,docfile.cxx}:
+ move SvKeyValue stuff from sfx2 to svtools
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx,
sfx2/inc/sfx2/sfxhtml.hxx, sfx2/source/bastyp/sfxhtml.cxx:
+ move ParseMetaOptions() and GetEncodingByMIME() from SfxHTMLParser (sfx2)
to HTMLParser (svtools)
+ make HTMLParser::ParseMetaOptions() a virtual function
+ HTMLParser::ParseMetaOptions() calls GetExtendedCompatibilityTextEncoding()
+ new template method HTMLParser::AddMetaUserDefined()
- svtools/source/svhtml/makefile.mk:
+ enable exceptions for parhtml.cxx
- dbaccess/source/ui/misc/HtmlReader.cxx,
sc/source/filter/html/htmlpars.cxx:
+ remove encoding related code duplication
- sw/source/filter/html/{swhtml{.hxx,.cxx},htmlfld.cxx}:
+ new SwHTMLParser::AddMetaUserDefined() for import of
DOCINFO field subtypes INFO[1-4]
+ do not use DocumentInfo for import of DOCINFO field subtypes INFO[1-4]
2009-03-31 17:01:35 +0200 mav r270288 : #i91214# fix typo
2009-03-31 15:19:41 +0200 mav r270285 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 15:00:36 +0200 mav r270284 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 12:19:13 +0200 mav r270270 : #i100123# taking the lock file over throws no exception
2009-03-30 13:57:21 +0200 mav r270227 : #i100351# fix the typo
2009-03-30 13:47:26 +0200 mav r270225 : #i99885# let OK be default button
2009-03-29 19:38:55 +0200 mav r270190 : CWS-TOOLING: rebase CWS fwk103 to trunk@270033 (milestone: DEV300:m45)
2009-03-16 16:39:48 +0100 mav r269558 : #i93558# convert the attributes as well
2009-03-13 15:35:55 +0100 mav r269488 : #i93558# improve manifest.xml parsing
2009-03-13 08:47:00 +0100 mav r269454 : #i96205# allow to remove password on SaveAs
2009-03-12 13:36:07 +0100 mav r269398 : #i91306# show special error in case of shared document
2009-03-12 13:33:35 +0100 mav r269397 : #i91306# introduce the new error-message
2009-03-12 11:40:42 +0100 mst r269378 : fix #i90877#
- svtools/source/uno/unoevent.cxx:
+ use proper operator delete[]
2009-02-26 15:23:10 +0100 mav r268526 : #i91214# do not use ATL
2009-02-26 14:19:06 +0100 mav r268516 : #i98909# integrate the patch
2009-02-10 17:29:52 +0100 cd r267568 : #i98649# Make sure that we catch the NoSuchElementException when a module is not installed.
2009-06-16 16:15:54 +00:00
|
|
|
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
|
2003-09-11 09:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new XUnbufferedStream ( xStream, rData );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffer, const ORef < EncryptionData > &rData )
|
|
|
|
{
|
|
|
|
if ( !rData.isValid() || !rData->aKey.getLength() )
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
sal_Int32 nSize = aReadBuffer.getLength();
|
|
|
|
|
|
|
|
// make a temporary cipher
|
|
|
|
rtlCipher aCipher;
|
2009-06-03 11:26:39 +00:00
|
|
|
StaticGetCipher ( rData, aCipher, sal_True );
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
Sequence < sal_Int8 > aDecryptBuffer ( nSize );
|
|
|
|
rtlDigest aDigest = rtl_digest_createSHA1();
|
|
|
|
rtlDigestError aDigestResult;
|
|
|
|
Sequence < sal_uInt8 > aDigestSeq ( RTL_DIGEST_LENGTH_SHA1 );
|
|
|
|
rtlCipherError aResult = rtl_cipher_decode ( aCipher,
|
|
|
|
aReadBuffer.getConstArray(),
|
|
|
|
nSize,
|
|
|
|
reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
|
|
|
|
nSize);
|
2006-06-20 05:13:42 +00:00
|
|
|
if(aResult != rtl_Cipher_E_None ) {
|
|
|
|
OSL_ASSERT ( aResult == rtl_Cipher_E_None);
|
|
|
|
}
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
aDigestResult = rtl_digest_updateSHA1 ( aDigest,
|
|
|
|
static_cast < const void * > ( aDecryptBuffer.getConstArray() ), nSize );
|
|
|
|
OSL_ASSERT ( aDigestResult == rtl_Digest_E_None );
|
|
|
|
|
|
|
|
aDigestResult = rtl_digest_getSHA1 ( aDigest, aDigestSeq.getArray(), RTL_DIGEST_LENGTH_SHA1 );
|
|
|
|
OSL_ASSERT ( aDigestResult == rtl_Digest_E_None );
|
|
|
|
|
|
|
|
// If we don't have a digest, then we have to assume that the password is correct
|
|
|
|
if ( rData->aDigest.getLength() != 0 &&
|
|
|
|
( aDigestSeq.getLength() != rData->aDigest.getLength() ||
|
|
|
|
0 != rtl_compareMemory ( aDigestSeq.getConstArray(),
|
|
|
|
rData->aDigest.getConstArray(),
|
|
|
|
aDigestSeq.getLength() ) ) )
|
|
|
|
{
|
|
|
|
// We should probably tell the user that the password they entered was wrong
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bRet = sal_True;
|
|
|
|
|
|
|
|
rtl_digest_destroySHA1 ( aDigest );
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ORef < EncryptionData > &rData )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
if ( rData->aKey.getLength() )
|
|
|
|
{
|
|
|
|
xSeek->seek( rEntry.nOffset );
|
|
|
|
sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
|
|
|
|
|
|
|
|
// Only want to read enough to verify the digest
|
|
|
|
nSize = nSize > n_ConstDigestLength ? n_ConstDigestLength : nSize;
|
2003-09-11 09:17:20 +00:00
|
|
|
Sequence < sal_Int8 > aReadBuffer ( nSize );
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
xStream->readBytes( aReadBuffer, nSize );
|
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
bRet = StaticHasValidPassword( aReadBuffer, rData );
|
2001-11-15 19:22:18 +00:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
2003-09-11 09:17:20 +00:00
|
|
|
|
2002-01-29 14:27:45 +00:00
|
|
|
#if 0
|
|
|
|
Reference < XInputStream > ZipFile::createFileStream(
|
|
|
|
ZipEntry & rEntry,
|
|
|
|
const ORef < EncryptionData > &rData,
|
|
|
|
sal_Bool bRawStream,
|
|
|
|
sal_Bool bIsEncrypted )
|
|
|
|
{
|
|
|
|
static OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
|
|
|
|
Reference < XInputStream > xTempStream = Reference < XInputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
|
|
|
|
return new XFileStream ( rEntry, xStream, xTempStream, rData, bRawStream, bIsEncrypted );
|
|
|
|
}
|
2001-07-04 13:56:37 +00:00
|
|
|
Reference < XInputStream > ZipFile::createMemoryStream(
|
|
|
|
ZipEntry & rEntry,
|
|
|
|
const ORef < EncryptionData > &rData,
|
2001-11-15 19:22:18 +00:00
|
|
|
sal_Bool bRawStream,
|
|
|
|
sal_Bool bIsEncrypted )
|
2001-07-04 13:56:37 +00:00
|
|
|
{
|
2001-09-05 17:50:48 +00:00
|
|
|
sal_Int32 nUncompressedSize, nEnd;
|
|
|
|
if (bRawStream)
|
|
|
|
{
|
|
|
|
nUncompressedSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
|
|
|
|
nEnd = rEntry.nOffset + nUncompressedSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nUncompressedSize = rEntry.nSize;
|
|
|
|
nEnd = rEntry.nMethod == DEFLATED ? rEntry.nOffset + rEntry.nCompressedSize : rEntry.nOffset + rEntry.nSize;
|
|
|
|
}
|
2001-07-04 13:56:37 +00:00
|
|
|
sal_Int32 nSize = rEntry.nMethod == DEFLATED ? rEntry.nCompressedSize : rEntry.nSize;
|
|
|
|
Sequence < sal_Int8 > aReadBuffer ( nSize ), aDecryptBuffer, aWriteBuffer;
|
|
|
|
rtlCipher aCipher;
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
// If the encryption key is zero, we need to return the raw stream. First check if
|
|
|
|
// we have the salt. If we have the salt, then check if we have the encryption key
|
|
|
|
// if not, return rawStream instead.
|
|
|
|
|
|
|
|
sal_Bool bHaveEncryptData = ( !rData.isEmpty() && rData->aSalt.getLength() && rData->aInitVector.getLength() && rData->nIterationCount != 0 ) ? sal_True : sal_False;
|
|
|
|
sal_Bool bMustDecrypt = ( !bRawStream && bHaveEncryptData && bIsEncrypted ) ? sal_True : sal_False;
|
2001-07-04 13:56:37 +00:00
|
|
|
|
|
|
|
if ( bMustDecrypt )
|
|
|
|
{
|
2009-06-03 11:26:39 +00:00
|
|
|
StaticGetCipher ( rData, aCipher, sal_True );
|
2001-07-04 13:56:37 +00:00
|
|
|
aDecryptBuffer.realloc ( nSize );
|
|
|
|
}
|
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
if ( nSize <0 )
|
2001-07-04 13:56:37 +00:00
|
|
|
throw IOException ( );
|
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
xSeek->seek( rEntry.nOffset );
|
2001-07-04 13:56:37 +00:00
|
|
|
xStream->readBytes( aReadBuffer, nSize ); // Now it holds the raw stuff from disk
|
|
|
|
|
|
|
|
if ( bMustDecrypt )
|
|
|
|
{
|
|
|
|
rtlCipherError aResult = rtl_cipher_decode ( aCipher,
|
|
|
|
aReadBuffer.getConstArray(),
|
|
|
|
nSize,
|
|
|
|
reinterpret_cast < sal_uInt8 * > (aDecryptBuffer.getArray()),
|
|
|
|
nSize);
|
|
|
|
OSL_ASSERT (aResult == rtl_Cipher_E_None);
|
|
|
|
aReadBuffer = aDecryptBuffer; // Now it holds the decrypted data
|
|
|
|
}
|
|
|
|
if (bRawStream || rEntry.nMethod == STORED)
|
|
|
|
aWriteBuffer = aReadBuffer; // bRawStream means the caller doesn't want it decompressed
|
|
|
|
else
|
|
|
|
{
|
2001-11-15 19:22:18 +00:00
|
|
|
aInflater.setInputSegment( aReadBuffer, 0, nSize );
|
2001-07-04 13:56:37 +00:00
|
|
|
aWriteBuffer.realloc( nUncompressedSize );
|
|
|
|
aInflater.doInflate( aWriteBuffer );
|
|
|
|
aInflater.reset();
|
|
|
|
}
|
2001-11-15 19:22:18 +00:00
|
|
|
|
|
|
|
if ( bHaveEncryptData && !bMustDecrypt && bIsEncrypted )
|
|
|
|
{
|
|
|
|
// if we have the data needed to decrypt it, but didn't want it decrypted (or
|
|
|
|
// we couldn't decrypt it due to wrong password), then we prepend this
|
|
|
|
// data to the stream
|
|
|
|
|
|
|
|
// Make a buffer big enough to hold both the header and the data itself
|
|
|
|
Sequence < sal_Int8 > aEncryptedDataHeader ( n_ConstHeaderSize +
|
|
|
|
rData->aInitVector.getLength() +
|
|
|
|
rData->aSalt.getLength() +
|
|
|
|
rData->aDigest.getLength() +
|
|
|
|
aWriteBuffer.getLength() );
|
|
|
|
sal_Int8 * pHeader = aEncryptedDataHeader.getArray();
|
|
|
|
StaticFillHeader ( rData, rEntry.nSize, pHeader );
|
|
|
|
memcpy ( pHeader, aWriteBuffer.getConstArray(), aWriteBuffer.getLength() );
|
|
|
|
|
|
|
|
// dump old buffer and point aWriteBuffer to the new one with the header
|
|
|
|
aWriteBuffer = aEncryptedDataHeader;
|
|
|
|
}
|
2001-07-04 13:56:37 +00:00
|
|
|
return Reference < XInputStream > ( new XMemoryStream ( aWriteBuffer ) );
|
|
|
|
}
|
2002-01-29 14:27:45 +00:00
|
|
|
#endif
|
2001-12-04 16:45:30 +00:00
|
|
|
Reference < XInputStream > ZipFile::createUnbufferedStream(
|
2009-09-08 08:54:47 +00:00
|
|
|
SotMutexHolderRef aMutexHolder,
|
2001-12-04 16:45:30 +00:00
|
|
|
ZipEntry & rEntry,
|
|
|
|
const ORef < EncryptionData > &rData,
|
2003-09-11 09:17:20 +00:00
|
|
|
sal_Int8 nStreamMode,
|
|
|
|
sal_Bool bIsEncrypted,
|
|
|
|
::rtl::OUString aMediaType )
|
2001-12-04 16:45:30 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
|
2001-12-04 16:45:30 +00:00
|
|
|
}
|
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-04-27 13:56:07 +00:00
|
|
|
ZipEnumeration * SAL_CALL ZipFile::entries( )
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2001-04-27 13:56:07 +00:00
|
|
|
return new ZipEnumeration ( aEntries );
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2000-12-04 10:30:09 +00:00
|
|
|
|
2001-07-04 13:56:37 +00:00
|
|
|
Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
|
2001-11-15 19:22:18 +00:00
|
|
|
const vos::ORef < EncryptionData > &rData,
|
2009-09-08 08:54:47 +00:00
|
|
|
sal_Bool bIsEncrypted,
|
|
|
|
SotMutexHolderRef aMutexHolder )
|
2001-07-04 13:56:37 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2001-09-05 17:50:48 +00:00
|
|
|
if ( rEntry.nOffset <= 0 )
|
|
|
|
readLOC( rEntry );
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2001-11-15 19:22:18 +00:00
|
|
|
// We want to return a rawStream if we either don't have a key or if the
|
|
|
|
// key is wrong
|
|
|
|
|
|
|
|
sal_Bool bNeedRawStream = rEntry.nMethod == STORED;
|
|
|
|
|
|
|
|
// if we have a digest, then this file is an encrypted one and we should
|
|
|
|
// check if we can decrypt it or not
|
|
|
|
if ( bIsEncrypted && !rData.isEmpty() && rData->aDigest.getLength() )
|
|
|
|
bNeedRawStream = !hasValidPassword ( rEntry, rData );
|
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
return createUnbufferedStream ( aMutexHolder,
|
|
|
|
rEntry,
|
2003-09-11 09:17:20 +00:00
|
|
|
rData,
|
|
|
|
bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
|
|
|
|
bIsEncrypted );
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
|
|
|
|
const vos::ORef < EncryptionData > &rData,
|
2009-09-08 08:54:47 +00:00
|
|
|
sal_Bool bIsEncrypted,
|
|
|
|
SotMutexHolderRef aMutexHolder )
|
2003-09-11 09:17:20 +00:00
|
|
|
throw ( packages::WrongPasswordException,
|
|
|
|
IOException,
|
|
|
|
ZipException,
|
|
|
|
RuntimeException )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
if ( rEntry.nOffset <= 0 )
|
|
|
|
readLOC( rEntry );
|
|
|
|
|
|
|
|
// An exception must be thrown in case stream is encrypted and
|
|
|
|
// there is no key or the key is wrong
|
|
|
|
sal_Bool bNeedRawStream = sal_False;
|
|
|
|
if ( bIsEncrypted )
|
|
|
|
{
|
|
|
|
// in case no digest is provided there is no way
|
|
|
|
// to detect password correctness
|
|
|
|
if ( rData.isEmpty() )
|
|
|
|
throw ZipException( OUString::createFromAscii( "Encrypted stream without encryption data!\n" ),
|
|
|
|
Reference< XInterface >() );
|
|
|
|
|
|
|
|
// if we have a digest, then this file is an encrypted one and we should
|
|
|
|
// check if we can decrypt it or not
|
|
|
|
OSL_ENSURE( rData->aDigest.getLength(), "Can't detect password correctness without digest!\n" );
|
|
|
|
if ( rData->aDigest.getLength() && !hasValidPassword ( rEntry, rData ) )
|
CWS-TOOLING: integrate CWS fwk103
2009-05-26 12:44:25 +0200 mst r272292 : #i100727#
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx:
+ fix warning: rename method to prevent overloading
2009-05-19 13:42:31 +0200 mav r272075 : #i101356# add comment
2009-05-19 10:56:24 +0200 mav r272062 : #i101356# register the singleton correctly
2009-05-19 10:25:42 +0200 mav r272060 : #i101356# register the singleton correctly
2009-05-18 12:48:48 +0200 mav r272013 : #i91306# fix the typo
2009-05-14 08:50:06 +0200 mav r271871 : #i101356# reduce the amount of macros
2009-05-13 13:26:08 +0200 mav r271858 : #i101356# reduce the amount of macros
2009-05-13 11:29:16 +0200 mav r271849 : #i101356# reduce the amount of macros
2009-05-12 12:09:42 +0200 mav r271815 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 12:03:20 +0200 mav r271814 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:58:48 +0200 mav r271813 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:53:05 +0200 mav r271812 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:48:36 +0200 mav r271810 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:43:45 +0200 mav r271809 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:39:38 +0200 mav r271808 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:37:38 +0200 mav r271806 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:33:58 +0200 mav r271805 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:30:01 +0200 mav r271804 : #i101356# allow to generate a small log if a document can not be stored
2009-05-06 17:43:38 +0200 mst r271607 : #i100727#
- svtools/source/svhtml/parhtml.cxx:
+ adapt code to renaming of HTML constants (sb107)
2009-05-05 11:14:18 +0200 mav r271507 : #i101222# avoid warning
2009-05-05 10:27:23 +0200 mav r271505 : #i101426# send the modified() notification only when the document can be modified
2009-05-05 10:25:07 +0200 mav r271504 : #i101426# send the modified() notification only when the document is modified
2009-05-05 08:42:48 +0200 mav r271497 : CWS-TOOLING: rebase CWS fwk103 to trunk@271427 (milestone: DEV300:m47)
2009-04-30 13:32:11 +0200 mav r271412 : #i100518# check the template folders quietly
2009-04-29 20:04:25 +0200 mst r271393 : - sw/source/filter/html/swhtml.cxx:
+ fix wrong initialization order in constructor
2009-04-28 12:28:46 +0200 mav r271319 : #i99142# set the error correctly
2009-04-28 08:44:48 +0200 mav r271305 : #i99050# clear hidden flag if necessary
2009-04-28 08:40:10 +0200 mav r271304 : #i99050# avoid crash
2009-04-22 07:40:11 +0200 mav r271056 : #i101093# lets not affect the performance
2009-04-15 09:30:47 +0200 cd r270820 : #i99771# Fix warnings for gcc 4.4
2009-04-15 09:19:52 +0200 cd r270819 : #i99771# Fix warnings for gcc 4.4
2009-04-15 08:42:34 +0200 cd r270817 : #i99771# Fix warnings for gcc 4.4
2009-04-14 14:31:01 +0200 mav r270768 : #i99493# fix typo
2009-04-01 12:45:43 +0200 mst r270317 : fix #i100727#
- svtools/inc/svtools/svparser.hxx, svtools/source/svrtf/svparser.cxx,
sfx2/inc/sfx2/docfile.hxx, sfx2/source/doc/{objmisc.cxx,docfile.cxx}:
+ move SvKeyValue stuff from sfx2 to svtools
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx,
sfx2/inc/sfx2/sfxhtml.hxx, sfx2/source/bastyp/sfxhtml.cxx:
+ move ParseMetaOptions() and GetEncodingByMIME() from SfxHTMLParser (sfx2)
to HTMLParser (svtools)
+ make HTMLParser::ParseMetaOptions() a virtual function
+ HTMLParser::ParseMetaOptions() calls GetExtendedCompatibilityTextEncoding()
+ new template method HTMLParser::AddMetaUserDefined()
- svtools/source/svhtml/makefile.mk:
+ enable exceptions for parhtml.cxx
- dbaccess/source/ui/misc/HtmlReader.cxx,
sc/source/filter/html/htmlpars.cxx:
+ remove encoding related code duplication
- sw/source/filter/html/{swhtml{.hxx,.cxx},htmlfld.cxx}:
+ new SwHTMLParser::AddMetaUserDefined() for import of
DOCINFO field subtypes INFO[1-4]
+ do not use DocumentInfo for import of DOCINFO field subtypes INFO[1-4]
2009-03-31 17:01:35 +0200 mav r270288 : #i91214# fix typo
2009-03-31 15:19:41 +0200 mav r270285 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 15:00:36 +0200 mav r270284 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 12:19:13 +0200 mav r270270 : #i100123# taking the lock file over throws no exception
2009-03-30 13:57:21 +0200 mav r270227 : #i100351# fix the typo
2009-03-30 13:47:26 +0200 mav r270225 : #i99885# let OK be default button
2009-03-29 19:38:55 +0200 mav r270190 : CWS-TOOLING: rebase CWS fwk103 to trunk@270033 (milestone: DEV300:m45)
2009-03-16 16:39:48 +0100 mav r269558 : #i93558# convert the attributes as well
2009-03-13 15:35:55 +0100 mav r269488 : #i93558# improve manifest.xml parsing
2009-03-13 08:47:00 +0100 mav r269454 : #i96205# allow to remove password on SaveAs
2009-03-12 13:36:07 +0100 mav r269398 : #i91306# show special error in case of shared document
2009-03-12 13:33:35 +0100 mav r269397 : #i91306# introduce the new error-message
2009-03-12 11:40:42 +0100 mst r269378 : fix #i90877#
- svtools/source/uno/unoevent.cxx:
+ use proper operator delete[]
2009-02-26 15:23:10 +0100 mav r268526 : #i91214# do not use ATL
2009-02-26 14:19:06 +0100 mav r268516 : #i98909# integrate the patch
2009-02-10 17:29:52 +0100 cd r267568 : #i98649# Make sure that we catch the NoSuchElementException when a module is not installed.
2009-06-16 16:15:54 +00:00
|
|
|
throw packages::WrongPasswordException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
|
2003-09-11 09:17:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
bNeedRawStream = ( rEntry.nMethod == STORED );
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
return createUnbufferedStream ( aMutexHolder,
|
|
|
|
rEntry,
|
2003-09-11 09:17:20 +00:00
|
|
|
rData,
|
|
|
|
bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
|
|
|
|
bIsEncrypted );
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2000-12-04 10:30:09 +00:00
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
|
2001-11-15 19:22:18 +00:00
|
|
|
const vos::ORef < EncryptionData > &rData,
|
2009-09-08 08:54:47 +00:00
|
|
|
sal_Bool bIsEncrypted,
|
|
|
|
SotMutexHolderRef aMutexHolder )
|
2001-07-04 13:56:37 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2000-12-13 16:00:47 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2001-09-05 17:50:48 +00:00
|
|
|
if ( rEntry.nOffset <= 0 )
|
|
|
|
readLOC( rEntry );
|
2001-07-04 13:56:37 +00:00
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
|
2003-09-11 09:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
|
|
|
|
ZipEntry& rEntry,
|
|
|
|
const vos::ORef < EncryptionData > &rData,
|
2009-09-08 08:54:47 +00:00
|
|
|
const ::rtl::OUString& aMediaType,
|
|
|
|
SotMutexHolderRef aMutexHolder )
|
2003-09-11 09:17:20 +00:00
|
|
|
throw ( packages::NoEncryptionException,
|
|
|
|
IOException,
|
|
|
|
ZipException,
|
|
|
|
RuntimeException )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-09-11 09:17:20 +00:00
|
|
|
if ( rData.isEmpty() )
|
CWS-TOOLING: integrate CWS fwk103
2009-05-26 12:44:25 +0200 mst r272292 : #i100727#
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx:
+ fix warning: rename method to prevent overloading
2009-05-19 13:42:31 +0200 mav r272075 : #i101356# add comment
2009-05-19 10:56:24 +0200 mav r272062 : #i101356# register the singleton correctly
2009-05-19 10:25:42 +0200 mav r272060 : #i101356# register the singleton correctly
2009-05-18 12:48:48 +0200 mav r272013 : #i91306# fix the typo
2009-05-14 08:50:06 +0200 mav r271871 : #i101356# reduce the amount of macros
2009-05-13 13:26:08 +0200 mav r271858 : #i101356# reduce the amount of macros
2009-05-13 11:29:16 +0200 mav r271849 : #i101356# reduce the amount of macros
2009-05-12 12:09:42 +0200 mav r271815 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 12:03:20 +0200 mav r271814 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:58:48 +0200 mav r271813 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:53:05 +0200 mav r271812 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:48:36 +0200 mav r271810 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:43:45 +0200 mav r271809 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:39:38 +0200 mav r271808 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:37:38 +0200 mav r271806 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:33:58 +0200 mav r271805 : #i101356# allow to generate a small log if a document can not be stored
2009-05-12 11:30:01 +0200 mav r271804 : #i101356# allow to generate a small log if a document can not be stored
2009-05-06 17:43:38 +0200 mst r271607 : #i100727#
- svtools/source/svhtml/parhtml.cxx:
+ adapt code to renaming of HTML constants (sb107)
2009-05-05 11:14:18 +0200 mav r271507 : #i101222# avoid warning
2009-05-05 10:27:23 +0200 mav r271505 : #i101426# send the modified() notification only when the document can be modified
2009-05-05 10:25:07 +0200 mav r271504 : #i101426# send the modified() notification only when the document is modified
2009-05-05 08:42:48 +0200 mav r271497 : CWS-TOOLING: rebase CWS fwk103 to trunk@271427 (milestone: DEV300:m47)
2009-04-30 13:32:11 +0200 mav r271412 : #i100518# check the template folders quietly
2009-04-29 20:04:25 +0200 mst r271393 : - sw/source/filter/html/swhtml.cxx:
+ fix wrong initialization order in constructor
2009-04-28 12:28:46 +0200 mav r271319 : #i99142# set the error correctly
2009-04-28 08:44:48 +0200 mav r271305 : #i99050# clear hidden flag if necessary
2009-04-28 08:40:10 +0200 mav r271304 : #i99050# avoid crash
2009-04-22 07:40:11 +0200 mav r271056 : #i101093# lets not affect the performance
2009-04-15 09:30:47 +0200 cd r270820 : #i99771# Fix warnings for gcc 4.4
2009-04-15 09:19:52 +0200 cd r270819 : #i99771# Fix warnings for gcc 4.4
2009-04-15 08:42:34 +0200 cd r270817 : #i99771# Fix warnings for gcc 4.4
2009-04-14 14:31:01 +0200 mav r270768 : #i99493# fix typo
2009-04-01 12:45:43 +0200 mst r270317 : fix #i100727#
- svtools/inc/svtools/svparser.hxx, svtools/source/svrtf/svparser.cxx,
sfx2/inc/sfx2/docfile.hxx, sfx2/source/doc/{objmisc.cxx,docfile.cxx}:
+ move SvKeyValue stuff from sfx2 to svtools
- svtools/inc/svtools/parhtml.hxx, svtools/source/svhtml/parhtml.cxx,
sfx2/inc/sfx2/sfxhtml.hxx, sfx2/source/bastyp/sfxhtml.cxx:
+ move ParseMetaOptions() and GetEncodingByMIME() from SfxHTMLParser (sfx2)
to HTMLParser (svtools)
+ make HTMLParser::ParseMetaOptions() a virtual function
+ HTMLParser::ParseMetaOptions() calls GetExtendedCompatibilityTextEncoding()
+ new template method HTMLParser::AddMetaUserDefined()
- svtools/source/svhtml/makefile.mk:
+ enable exceptions for parhtml.cxx
- dbaccess/source/ui/misc/HtmlReader.cxx,
sc/source/filter/html/htmlpars.cxx:
+ remove encoding related code duplication
- sw/source/filter/html/{swhtml{.hxx,.cxx},htmlfld.cxx}:
+ new SwHTMLParser::AddMetaUserDefined() for import of
DOCINFO field subtypes INFO[1-4]
+ do not use DocumentInfo for import of DOCINFO field subtypes INFO[1-4]
2009-03-31 17:01:35 +0200 mav r270288 : #i91214# fix typo
2009-03-31 15:19:41 +0200 mav r270285 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 15:00:36 +0200 mav r270284 : #i100123# allow to turn OOo locking mechanics off
2009-03-31 12:19:13 +0200 mav r270270 : #i100123# taking the lock file over throws no exception
2009-03-30 13:57:21 +0200 mav r270227 : #i100351# fix the typo
2009-03-30 13:47:26 +0200 mav r270225 : #i99885# let OK be default button
2009-03-29 19:38:55 +0200 mav r270190 : CWS-TOOLING: rebase CWS fwk103 to trunk@270033 (milestone: DEV300:m45)
2009-03-16 16:39:48 +0100 mav r269558 : #i93558# convert the attributes as well
2009-03-13 15:35:55 +0100 mav r269488 : #i93558# improve manifest.xml parsing
2009-03-13 08:47:00 +0100 mav r269454 : #i96205# allow to remove password on SaveAs
2009-03-12 13:36:07 +0100 mav r269398 : #i91306# show special error in case of shared document
2009-03-12 13:33:35 +0100 mav r269397 : #i91306# introduce the new error-message
2009-03-12 11:40:42 +0100 mst r269378 : fix #i90877#
- svtools/source/uno/unoevent.cxx:
+ use proper operator delete[]
2009-02-26 15:23:10 +0100 mav r268526 : #i91214# do not use ATL
2009-02-26 14:19:06 +0100 mav r268516 : #i98909# integrate the patch
2009-02-10 17:29:52 +0100 cd r267568 : #i98649# Make sure that we catch the NoSuchElementException when a module is not installed.
2009-06-16 16:15:54 +00:00
|
|
|
throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
|
2003-09-11 09:17:20 +00:00
|
|
|
|
|
|
|
if ( rEntry.nOffset <= 0 )
|
|
|
|
readLOC( rEntry );
|
|
|
|
|
2009-09-08 08:54:47 +00:00
|
|
|
return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, sal_True, aMediaType );
|
2000-12-13 16:00:47 +00:00
|
|
|
}
|
|
|
|
|
2001-04-27 13:56:07 +00:00
|
|
|
sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
|
2001-07-04 13:56:37 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
sal_Int32 nTestSig, nTime, nCRC, nSize, nCompressedSize;
|
2009-09-17 13:53:54 +00:00
|
|
|
sal_Int16 nVersion, nFlag, nHow, nPathLen, nExtraLen;
|
2000-11-13 12:38:03 +00:00
|
|
|
sal_Int32 nPos = -rEntry.nOffset;
|
|
|
|
|
|
|
|
aGrabber.seek(nPos);
|
|
|
|
aGrabber >> nTestSig;
|
|
|
|
|
|
|
|
if (nTestSig != LOCSIG)
|
2005-03-15 10:50:19 +00:00
|
|
|
throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid LOC header (bad signature") ), Reference < XInterface > () );
|
2000-11-13 12:38:03 +00:00
|
|
|
aGrabber >> nVersion;
|
|
|
|
aGrabber >> nFlag;
|
|
|
|
aGrabber >> nHow;
|
|
|
|
aGrabber >> nTime;
|
|
|
|
aGrabber >> nCRC;
|
|
|
|
aGrabber >> nCompressedSize;
|
|
|
|
aGrabber >> nSize;
|
2009-09-17 13:53:54 +00:00
|
|
|
aGrabber >> nPathLen;
|
2000-11-13 12:38:03 +00:00
|
|
|
aGrabber >> nExtraLen;
|
2009-09-17 13:53:54 +00:00
|
|
|
rEntry.nOffset = static_cast < sal_Int32 > (aGrabber.getPosition()) + nPathLen + nExtraLen;
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
// read always in UTF8, some tools seem not to set UTF8 bit
|
|
|
|
uno::Sequence < sal_Int8 > aNameBuffer( nPathLen );
|
|
|
|
sal_Int32 nRead = aGrabber.readBytes( aNameBuffer, nPathLen );
|
|
|
|
if ( nRead < aNameBuffer.getLength() )
|
|
|
|
aNameBuffer.realloc( nRead );
|
|
|
|
|
|
|
|
::rtl::OUString sLOCPath = rtl::OUString::intern( (sal_Char *) aNameBuffer.getArray(),
|
|
|
|
aNameBuffer.getLength(),
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
|
|
|
|
|
|
|
if ( rEntry.nPathLen == -1 ) // the file was created
|
|
|
|
{
|
|
|
|
rEntry.nPathLen = nPathLen;
|
|
|
|
rEntry.sPath = sLOCPath;
|
|
|
|
}
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
// the method can be reset for internal use so it is not checked
|
|
|
|
sal_Bool bBroken = rEntry.nVersion != nVersion
|
|
|
|
|| rEntry.nFlag != nFlag
|
|
|
|
|| rEntry.nTime != nTime
|
2009-09-17 13:53:54 +00:00
|
|
|
|| rEntry.nPathLen != nPathLen
|
|
|
|
|| !rEntry.sPath.equals( sLOCPath );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
2005-03-15 10:50:19 +00:00
|
|
|
if ( bBroken && !bRecoveryMode )
|
|
|
|
throw ZipIOException( OUString( RTL_CONSTASCII_USTRINGPARAM( "The stream seems to be broken!" ) ),
|
2003-03-26 13:16:07 +00:00
|
|
|
Reference< XInterface >() );
|
|
|
|
|
2000-11-13 12:38:03 +00:00
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 ZipFile::findEND( )
|
2001-07-04 13:56:37 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
// this method is called in constructor only, no need for mutex
|
2001-08-08 17:23:04 +00:00
|
|
|
sal_Int32 nLength, nPos, nEnd;
|
|
|
|
Sequence < sal_Int8 > aBuffer;
|
2001-06-15 14:25:10 +00:00
|
|
|
try
|
|
|
|
{
|
2001-08-08 17:23:04 +00:00
|
|
|
nLength = static_cast <sal_Int32 > (aGrabber.getLength());
|
|
|
|
if (nLength == 0 || nLength < ENDHDR)
|
2001-06-15 14:25:10 +00:00
|
|
|
return -1;
|
2001-08-08 17:23:04 +00:00
|
|
|
nPos = nLength - ENDHDR - ZIP_MAXNAMELEN;
|
|
|
|
nEnd = nPos >= 0 ? nPos : 0 ;
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-08-08 17:23:04 +00:00
|
|
|
aGrabber.seek( nEnd );
|
|
|
|
aGrabber.readBytes ( aBuffer, nLength - nEnd );
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-08-08 17:23:04 +00:00
|
|
|
const sal_Int8 *pBuffer = aBuffer.getConstArray();
|
2001-06-14 16:36:15 +00:00
|
|
|
|
2001-08-08 17:23:04 +00:00
|
|
|
nPos = nLength - nEnd - ENDHDR;
|
|
|
|
while ( nPos >= 0 )
|
|
|
|
{
|
|
|
|
if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 5 && pBuffer[nPos+3] == 6 )
|
|
|
|
return nPos + nEnd;
|
|
|
|
nPos--;
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-15 14:25:10 +00:00
|
|
|
catch ( IllegalArgumentException& )
|
|
|
|
{
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
2001-06-15 14:25:10 +00:00
|
|
|
}
|
2001-08-08 17:23:04 +00:00
|
|
|
catch ( NotConnectedException& )
|
|
|
|
{
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
2001-08-08 17:23:04 +00:00
|
|
|
}
|
|
|
|
catch ( BufferSizeExceededException& )
|
|
|
|
{
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
2001-08-08 17:23:04 +00:00
|
|
|
}
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 ZipFile::readCEN()
|
2001-07-04 13:56:37 +00:00
|
|
|
throw(IOException, ZipException, RuntimeException)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
// this method is called in constructor only, no need for mutex
|
2001-09-14 14:03:35 +00:00
|
|
|
sal_Int32 nCenLen, nCenPos = -1, nCenOff, nEndPos, nLocPos;
|
2003-04-28 14:46:49 +00:00
|
|
|
sal_uInt16 nCount, nTotal;
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-06-15 14:25:10 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
nEndPos = findEND();
|
|
|
|
if (nEndPos == -1)
|
|
|
|
return -1;
|
|
|
|
aGrabber.seek(nEndPos + ENDTOT);
|
|
|
|
aGrabber >> nTotal;
|
|
|
|
aGrabber >> nCenLen;
|
|
|
|
aGrabber >> nCenOff;
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2004-02-04 11:28:06 +00:00
|
|
|
if ( nTotal * CENHDR > nCenLen )
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "invalid END header (bad entry count)") ), Reference < XInterface > () );
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-09-14 14:03:35 +00:00
|
|
|
if ( nTotal > ZIP_MAXENTRIES )
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "too many entries in ZIP File") ), Reference < XInterface > () );
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-09-14 14:03:35 +00:00
|
|
|
if ( nCenLen < 0 || nCenLen > nEndPos )
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () );
|
2000-12-04 10:30:09 +00:00
|
|
|
|
2001-06-15 14:25:10 +00:00
|
|
|
nCenPos = nEndPos - nCenLen;
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-09-14 14:03:35 +00:00
|
|
|
if ( nCenOff < 0 || nCenOff > nCenPos )
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid END header (bad central directory size)") ), Reference < XInterface > () );
|
2000-11-13 12:38:03 +00:00
|
|
|
|
2001-06-15 14:25:10 +00:00
|
|
|
nLocPos = nCenPos - nCenOff;
|
2001-09-14 14:03:35 +00:00
|
|
|
aGrabber.seek( nCenPos );
|
|
|
|
Sequence < sal_Int8 > aCENBuffer ( nCenLen );
|
|
|
|
sal_Int64 nRead = aGrabber.readBytes ( aCENBuffer, nCenLen );
|
|
|
|
if ( static_cast < sal_Int64 > ( nCenLen ) != nRead )
|
|
|
|
throw ZipException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Error reading CEN into memory buffer!") ), Reference < XInterface > () );
|
|
|
|
|
|
|
|
MemoryByteGrabber aMemGrabber ( aCENBuffer );
|
|
|
|
|
|
|
|
ZipEntry aEntry;
|
|
|
|
sal_Int32 nTestSig;
|
2003-03-26 13:16:07 +00:00
|
|
|
sal_Int16 nCommentLen;
|
2000-12-04 10:30:09 +00:00
|
|
|
|
2001-06-15 14:25:10 +00:00
|
|
|
for (nCount = 0 ; nCount < nTotal; nCount++)
|
2000-11-13 12:38:03 +00:00
|
|
|
{
|
2001-09-14 14:03:35 +00:00
|
|
|
aMemGrabber >> nTestSig;
|
|
|
|
if ( nTestSig != CENSIG )
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad signature)") ), Reference < XInterface > () );
|
|
|
|
|
|
|
|
aMemGrabber.skipBytes ( 2 );
|
|
|
|
aMemGrabber >> aEntry.nVersion;
|
|
|
|
|
|
|
|
if ( ( aEntry.nVersion & 1 ) == 1 )
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (encrypted entry)") ), Reference < XInterface > () );
|
|
|
|
|
|
|
|
aMemGrabber >> aEntry.nFlag;
|
|
|
|
aMemGrabber >> aEntry.nMethod;
|
|
|
|
|
|
|
|
if ( aEntry.nMethod != STORED && aEntry.nMethod != DEFLATED)
|
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Invalid CEN header (bad compression method)") ), Reference < XInterface > () );
|
|
|
|
|
|
|
|
aMemGrabber >> aEntry.nTime;
|
|
|
|
aMemGrabber >> aEntry.nCrc;
|
|
|
|
aMemGrabber >> aEntry.nCompressedSize;
|
|
|
|
aMemGrabber >> aEntry.nSize;
|
2009-09-17 13:53:54 +00:00
|
|
|
aMemGrabber >> aEntry.nPathLen;
|
2003-03-26 13:16:07 +00:00
|
|
|
aMemGrabber >> aEntry.nExtraLen;
|
2001-09-14 14:03:35 +00:00
|
|
|
aMemGrabber >> nCommentLen;
|
|
|
|
aMemGrabber.skipBytes ( 8 );
|
|
|
|
aMemGrabber >> aEntry.nOffset;
|
|
|
|
|
|
|
|
aEntry.nOffset += nLocPos;
|
|
|
|
aEntry.nOffset *= -1;
|
|
|
|
|
2010-06-03 16:47:33 +02:00
|
|
|
if ( aEntry.nPathLen < 0 )
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected name length" ) ), Reference < XInterface > () );
|
2001-09-14 14:03:35 +00:00
|
|
|
|
2010-06-03 16:47:33 +02:00
|
|
|
if ( nCommentLen < 0 )
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected comment length" ) ), Reference < XInterface > () );
|
2001-09-14 14:03:35 +00:00
|
|
|
|
2010-06-03 16:47:33 +02:00
|
|
|
if ( aEntry.nExtraLen < 0 )
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "unexpected extra header info length") ), Reference < XInterface > () );
|
2001-09-14 14:03:35 +00:00
|
|
|
|
2009-02-12 10:27:21 +00:00
|
|
|
// read always in UTF8, some tools seem not to set UTF8 bit
|
2009-09-17 13:53:54 +00:00
|
|
|
aEntry.sPath = rtl::OUString::intern ( (sal_Char *) aMemGrabber.getCurrentPos(),
|
|
|
|
aEntry.nPathLen,
|
2009-02-12 10:27:21 +00:00
|
|
|
RTL_TEXTENCODING_UTF8 );
|
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( aEntry.sPath, sal_True ) )
|
2009-02-12 10:27:21 +00:00
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip entry has an invalid name.") ), Reference < XInterface > () );
|
2001-09-14 14:03:35 +00:00
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
aMemGrabber.skipBytes( aEntry.nPathLen + aEntry.nExtraLen + nCommentLen );
|
|
|
|
aEntries[aEntry.sPath] = aEntry;
|
2000-11-13 12:38:03 +00:00
|
|
|
}
|
2000-12-04 10:30:09 +00:00
|
|
|
|
2001-06-15 14:25:10 +00:00
|
|
|
if (nCount != nTotal)
|
2001-09-14 14:03:35 +00:00
|
|
|
throw ZipException(OUString( RTL_CONSTASCII_USTRINGPARAM ( "Count != Total") ), Reference < XInterface > () );
|
2001-06-15 14:25:10 +00:00
|
|
|
}
|
|
|
|
catch ( IllegalArgumentException & )
|
|
|
|
{
|
|
|
|
// seek can throw this...
|
|
|
|
nCenPos = -1; // make sure we return -1 to indicate an error
|
|
|
|
}
|
2000-11-13 12:38:03 +00:00
|
|
|
return nCenPos;
|
|
|
|
}
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
sal_Int32 ZipFile::recover()
|
|
|
|
throw(IOException, ZipException, RuntimeException)
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
sal_Int32 nLength;
|
|
|
|
Sequence < sal_Int8 > aBuffer;
|
|
|
|
Sequence < sal_Int32 > aHeaderOffsets;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
nLength = static_cast <sal_Int32 > (aGrabber.getLength());
|
|
|
|
if (nLength == 0 || nLength < ENDHDR)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
aGrabber.seek( 0 );
|
|
|
|
|
2011-01-03 18:09:17 +01:00
|
|
|
// TODO/LATER: let the files > 2Gb handle the 2Gb border correctly ( if header is splitted )
|
|
|
|
for( sal_Int32 nGenPos = 0; aGrabber.readBytes( aBuffer, SAL_MAX_INT32 ) && aBuffer.getLength() > 30; )
|
2003-03-26 13:16:07 +00:00
|
|
|
{
|
|
|
|
const sal_Int8 *pBuffer = aBuffer.getConstArray();
|
|
|
|
sal_Int32 nBufSize = aBuffer.getLength();
|
|
|
|
|
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
while( nPos < nBufSize - 16 )
|
|
|
|
{
|
|
|
|
if ( nPos < nBufSize - 30 && pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 3 && pBuffer[nPos+3] == 4 )
|
|
|
|
{
|
|
|
|
ZipEntry aEntry;
|
|
|
|
MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 26 ) );
|
|
|
|
|
|
|
|
aMemGrabber >> aEntry.nVersion;
|
|
|
|
if ( ( aEntry.nVersion & 1 ) != 1 )
|
|
|
|
{
|
|
|
|
aMemGrabber >> aEntry.nFlag;
|
|
|
|
aMemGrabber >> aEntry.nMethod;
|
|
|
|
|
|
|
|
if ( aEntry.nMethod == STORED || aEntry.nMethod == DEFLATED )
|
|
|
|
{
|
|
|
|
aMemGrabber >> aEntry.nTime;
|
|
|
|
aMemGrabber >> aEntry.nCrc;
|
|
|
|
aMemGrabber >> aEntry.nCompressedSize;
|
|
|
|
aMemGrabber >> aEntry.nSize;
|
2009-09-17 13:53:54 +00:00
|
|
|
aMemGrabber >> aEntry.nPathLen;
|
2003-03-26 13:16:07 +00:00
|
|
|
aMemGrabber >> aEntry.nExtraLen;
|
|
|
|
|
|
|
|
sal_Int32 nDescrLength =
|
|
|
|
( aEntry.nMethod == DEFLATED && ( aEntry.nFlag & 8 ) ) ?
|
|
|
|
16 : 0;
|
|
|
|
|
2003-07-01 14:11:54 +00:00
|
|
|
|
|
|
|
// This is a quick fix for OOo1.1RC
|
|
|
|
// For OOo2.0 the whole package must be switched to unsigned values
|
|
|
|
if ( aEntry.nCompressedSize < 0 ) aEntry.nCompressedSize = 0x7FFFFFFF;
|
|
|
|
if ( aEntry.nSize < 0 ) aEntry.nSize = 0x7FFFFFFF;
|
2009-09-17 13:53:54 +00:00
|
|
|
if ( aEntry.nPathLen < 0 ) aEntry.nPathLen = 0x7FFF;
|
2003-07-01 14:11:54 +00:00
|
|
|
if ( aEntry.nExtraLen < 0 ) aEntry.nExtraLen = 0x7FFF;
|
|
|
|
// End of quick fix
|
|
|
|
|
2009-12-16 14:02:04 +00:00
|
|
|
sal_Int32 nDataSize = ( aEntry.nMethod == DEFLATED ) ? aEntry.nCompressedSize : aEntry.nSize;
|
|
|
|
sal_Int32 nBlockLength = nDataSize + aEntry.nPathLen + aEntry.nExtraLen + 30 + nDescrLength;
|
2010-06-03 16:47:33 +02:00
|
|
|
if ( aEntry.nPathLen >= 0 && aEntry.nExtraLen >= 0
|
2003-03-26 13:16:07 +00:00
|
|
|
&& ( nGenPos + nPos + nBlockLength ) <= nLength )
|
|
|
|
{
|
2009-02-12 10:27:21 +00:00
|
|
|
// read always in UTF8, some tools seem not to set UTF8 bit
|
2009-09-17 13:53:54 +00:00
|
|
|
if( nPos + 30 + aEntry.nPathLen <= nBufSize )
|
|
|
|
aEntry.sPath = OUString ( (sal_Char *) &pBuffer[nPos + 30],
|
|
|
|
aEntry.nPathLen,
|
2009-02-12 10:27:21 +00:00
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2003-03-26 13:16:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Sequence < sal_Int8 > aFileName;
|
|
|
|
aGrabber.seek( nGenPos + nPos + 30 );
|
2009-09-17 13:53:54 +00:00
|
|
|
aGrabber.readBytes( aFileName, aEntry.nPathLen );
|
|
|
|
aEntry.sPath = OUString ( (sal_Char *) aFileName.getArray(),
|
2003-03-26 13:16:07 +00:00
|
|
|
aFileName.getLength(),
|
2009-02-12 10:27:21 +00:00
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2009-09-17 13:53:54 +00:00
|
|
|
aEntry.nPathLen = static_cast< sal_Int16 >(aFileName.getLength());
|
2003-03-26 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
aEntry.nOffset = nGenPos + nPos + 30 + aEntry.nPathLen + aEntry.nExtraLen;
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
if ( ( aEntry.nSize || aEntry.nCompressedSize ) && !checkSizeAndCRC( aEntry ) )
|
|
|
|
{
|
|
|
|
aEntry.nCrc = 0;
|
|
|
|
aEntry.nCompressedSize = 0;
|
|
|
|
aEntry.nSize = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-17 13:53:54 +00:00
|
|
|
if ( aEntries.find( aEntry.sPath ) == aEntries.end() )
|
|
|
|
aEntries[aEntry.sPath] = aEntry;
|
2003-03-26 13:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nPos += 4;
|
|
|
|
}
|
|
|
|
else if (pBuffer[nPos] == 'P' && pBuffer[nPos+1] == 'K' && pBuffer[nPos+2] == 7 && pBuffer[nPos+3] == 8 )
|
|
|
|
{
|
|
|
|
sal_Int32 nCompressedSize, nSize, nCRC32;
|
|
|
|
MemoryByteGrabber aMemGrabber ( Sequence< sal_Int8 >( ((sal_Int8*)(&(pBuffer[nPos+4]))), 12 ) );
|
|
|
|
aMemGrabber >> nCRC32;
|
|
|
|
aMemGrabber >> nCompressedSize;
|
|
|
|
aMemGrabber >> nSize;
|
|
|
|
|
|
|
|
for( EntryHash::iterator aIter = aEntries.begin(); aIter != aEntries.end(); aIter++ )
|
|
|
|
{
|
|
|
|
ZipEntry aTmp = (*aIter).second;
|
2008-07-08 07:28:23 +00:00
|
|
|
|
|
|
|
// this is a broken package, accept this block not only for DEFLATED streams
|
|
|
|
if( (*aIter).second.nFlag & 8 )
|
2003-03-26 13:16:07 +00:00
|
|
|
{
|
|
|
|
sal_Int32 nStreamOffset = nGenPos + nPos - nCompressedSize;
|
|
|
|
if ( nStreamOffset == (*aIter).second.nOffset && nCompressedSize > (*aIter).second.nCompressedSize )
|
|
|
|
{
|
2008-07-08 07:28:23 +00:00
|
|
|
// only DEFLATED blocks need to be checked
|
|
|
|
sal_Bool bAcceptBlock = ( (*aIter).second.nMethod == STORED && nCompressedSize == nSize );
|
|
|
|
|
|
|
|
if ( !bAcceptBlock )
|
|
|
|
{
|
|
|
|
sal_Int32 nRealSize = 0, nRealCRC = 0;
|
|
|
|
getSizeAndCRC( nStreamOffset, nCompressedSize, &nRealSize, &nRealCRC );
|
|
|
|
bAcceptBlock = ( nRealSize == nSize && nRealCRC == nCRC32 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bAcceptBlock )
|
2003-03-26 13:16:07 +00:00
|
|
|
{
|
|
|
|
(*aIter).second.nCrc = nCRC32;
|
|
|
|
(*aIter).second.nCompressedSize = nCompressedSize;
|
|
|
|
(*aIter).second.nSize = nSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
// for now ignore clearly broken streams
|
|
|
|
else if( !(*aIter).second.nCompressedSize )
|
|
|
|
{
|
|
|
|
(*aIter).second.nCrc = nCRC32;
|
|
|
|
sal_Int32 nRealStreamSize = nGenPos + nPos - (*aIter).second.nOffset;
|
|
|
|
(*aIter).second.nCompressedSize = nGenPos + nPos - (*aIter).second.nOffset;
|
|
|
|
(*aIter).second.nSize = nSize;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nPos += 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nGenPos += nPos;
|
|
|
|
aGrabber.seek( nGenPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch ( IllegalArgumentException& )
|
|
|
|
{
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
|
|
|
}
|
|
|
|
catch ( NotConnectedException& )
|
|
|
|
{
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
|
|
|
}
|
|
|
|
catch ( BufferSizeExceededException& )
|
|
|
|
{
|
|
|
|
throw ZipException( OUString( RTL_CONSTASCII_USTRINGPARAM ( "Zip END signature not found!") ), Reference < XInterface > () );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool ZipFile::checkSizeAndCRC( const ZipEntry& aEntry )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
sal_Int32 nSize = 0, nCRC = 0;
|
|
|
|
|
|
|
|
if( aEntry.nMethod == STORED )
|
|
|
|
return ( getCRC( aEntry.nOffset, aEntry.nSize ) == aEntry.nCrc );
|
|
|
|
|
|
|
|
getSizeAndCRC( aEntry.nOffset, aEntry.nCompressedSize, &nSize, &nCRC );
|
|
|
|
return ( aEntry.nSize == nSize && aEntry.nCrc == nCRC );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 ZipFile::getCRC( sal_Int32 nOffset, sal_Int32 nSize )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
Sequence < sal_Int8 > aBuffer;
|
|
|
|
CRC32 aCRC;
|
2004-02-04 11:28:06 +00:00
|
|
|
sal_Int32 nBlockSize = ::std::min( nSize, static_cast< sal_Int32 >( 32000 ) );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
aGrabber.seek( nOffset );
|
|
|
|
for ( int ind = 0;
|
|
|
|
aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nSize;
|
|
|
|
ind++ )
|
|
|
|
{
|
|
|
|
aCRC.updateSegment( aBuffer, 0, ::std::min( nBlockSize, nSize - ind * nBlockSize ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aCRC.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZipFile::getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC )
|
|
|
|
{
|
2009-10-21 14:48:59 +00:00
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2003-03-26 13:16:07 +00:00
|
|
|
Sequence < sal_Int8 > aBuffer;
|
|
|
|
CRC32 aCRC;
|
|
|
|
sal_Int32 nRealSize = 0;
|
2006-06-20 05:13:42 +00:00
|
|
|
Inflater aInflaterLocal( sal_True );
|
2004-02-04 11:28:06 +00:00
|
|
|
sal_Int32 nBlockSize = ::std::min( nCompressedSize, static_cast< sal_Int32 >( 32000 ) );
|
2003-03-26 13:16:07 +00:00
|
|
|
|
|
|
|
aGrabber.seek( nOffset );
|
|
|
|
for ( int ind = 0;
|
2006-06-20 05:13:42 +00:00
|
|
|
!aInflaterLocal.finished() && aGrabber.readBytes( aBuffer, nBlockSize ) && ind * nBlockSize < nCompressedSize;
|
2003-03-26 13:16:07 +00:00
|
|
|
ind++ )
|
|
|
|
{
|
|
|
|
Sequence < sal_Int8 > aData( nBlockSize );
|
|
|
|
sal_Int32 nLastInflated = 0;
|
|
|
|
sal_Int32 nInBlock = 0;
|
|
|
|
|
2006-06-20 05:13:42 +00:00
|
|
|
aInflaterLocal.setInput( aBuffer );
|
2003-03-26 13:16:07 +00:00
|
|
|
do
|
|
|
|
{
|
2006-06-20 05:13:42 +00:00
|
|
|
nLastInflated = aInflaterLocal.doInflateSegment( aData, 0, nBlockSize );
|
2003-03-26 13:16:07 +00:00
|
|
|
aCRC.updateSegment( aData, 0, nLastInflated );
|
|
|
|
nInBlock += nLastInflated;
|
|
|
|
} while( !aInflater.finished() && nLastInflated );
|
|
|
|
|
|
|
|
nRealSize += nInBlock;
|
|
|
|
}
|
|
|
|
|
2010-07-28 14:17:26 +02:00
|
|
|
*nSize = nRealSize;
|
|
|
|
*nCRC = aCRC.getValue();
|
2003-03-26 13:16:07 +00:00
|
|
|
}
|
2010-07-28 14:17:26 +02:00
|
|
|
|