summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package/inc/ByteGrabber.hxx4
-rw-r--r--package/inc/ZipFile.hxx2
-rw-r--r--package/source/zipapi/ByteGrabber.cxx21
-rw-r--r--package/source/zipapi/ZipFile.cxx26
4 files changed, 53 insertions, 0 deletions
diff --git a/package/inc/ByteGrabber.hxx b/package/inc/ByteGrabber.hxx
index 725b2819f371..d4869845f066 100644
--- a/package/inc/ByteGrabber.hxx
+++ b/package/inc/ByteGrabber.hxx
@@ -38,12 +38,16 @@
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <osl/mutex.hxx>
+
namespace com { namespace sun { namespace star {
namespace io { class XSeekable; class XInputStream; }
} } }
class ByteGrabber
{
protected:
+ ::osl::Mutex m_aMutex;
+
com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xStream;
com::sun::star::uno::Reference < com::sun::star::io::XSeekable > xSeek;
com::sun::star::uno::Sequence < sal_Int8 > aSequence;
diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx
index a954a1691c4b..a4129f4fbbfe 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -65,6 +65,8 @@ class EncryptionData;
class ZipFile
{
protected:
+ ::osl::Mutex m_aMutex;
+
::rtl::OUString sComment; /* zip file comment */
EntryHash aEntries;
ByteGrabber aGrabber;
diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx
index 7e8433d77837..84cd6465f7bf 100644
--- a/package/source/zipapi/ByteGrabber.cxx
+++ b/package/source/zipapi/ByteGrabber.cxx
@@ -51,8 +51,10 @@ ByteGrabber::ByteGrabber(uno::Reference < io::XInputStream > xIstream)
ByteGrabber::~ByteGrabber()
{
}
+
void ByteGrabber::setInputStream (uno::Reference < io::XInputStream > xNewStream)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
xStream = xNewStream;
xSeek = uno::Reference < io::XSeekable > (xNewStream, uno::UNO_QUERY);
}
@@ -62,6 +64,7 @@ sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
sal_Int32 nBytesToRead )
throw(io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
return xStream->readBytes(aData, nBytesToRead );
}
@@ -69,6 +72,7 @@ sal_Int32 SAL_CALL ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData,
sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location )
throw(lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
if (xSeek.is() )
{
sal_Int64 nLen = xSeek->getLength();
@@ -82,32 +86,40 @@ sal_Int64 SAL_CALL ByteGrabber::seek( sal_Int64 location )
else
throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
+
sal_Int64 SAL_CALL ByteGrabber::getPosition( )
throw(io::IOException, uno::RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
if (xSeek.is() )
return xSeek->getPosition();
else
throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
+
sal_Int64 SAL_CALL ByteGrabber::getLength( )
throw(io::IOException, uno::RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
if (xSeek.is() )
return xSeek->getLength();
else
throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
}
+
ByteGrabber& ByteGrabber::operator >> (sal_Int8& rInt8)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
if (xStream->readBytes(aSequence,1) != 1)
rInt8 = 0;
else
rInt8 = aSequence[0] & 0xFF;
return *this;
}
+
ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
if (xStream->readBytes ( aSequence, 2) != 2)
rInt16 = 0;
else
@@ -119,8 +131,11 @@ ByteGrabber& ByteGrabber::operator >> (sal_Int16& rInt16)
}
return *this;
}
+
ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if (xStream->readBytes(aSequence, 4) != 4)
rInt32 = 0;
else
@@ -137,6 +152,8 @@ ByteGrabber& ByteGrabber::operator >> (sal_Int32& rInt32)
ByteGrabber& ByteGrabber::operator >> (sal_uInt8& rInt8)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if (xStream->readBytes(aSequence,1) != 1)
rInt8 = 0;
else
@@ -145,6 +162,8 @@ ByteGrabber& ByteGrabber::operator >> (sal_uInt8& rInt8)
}
ByteGrabber& ByteGrabber::operator >> (sal_uInt16& rInt16)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if (xStream->readBytes(aSequence, 2) != 2)
rInt16 = 0;
else
@@ -158,6 +177,8 @@ ByteGrabber& ByteGrabber::operator >> (sal_uInt16& rInt16)
}
ByteGrabber& ByteGrabber::operator >> (sal_uInt32& ruInt32)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if (xStream->readBytes(aSequence, 4) != 4)
ruInt32 = 0;
else
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
index 246cbd889015..f6dafac4cb6a 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -122,6 +122,8 @@ ZipFile::~ZipFile()
void ZipFile::setInputStream ( Reference < XInputStream > xNewStream )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
xStream = xNewStream;
xSeek = Reference < XSeekable > ( xStream, UNO_QUERY );
aGrabber.setInputStream ( xStream );
@@ -381,6 +383,8 @@ sal_Bool ZipFile::StaticHasValidPassword( const Sequence< sal_Int8 > &aReadBuffe
sal_Bool ZipFile::hasValidPassword ( ZipEntry & rEntry, const ORef < EncryptionData > &rData )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
sal_Bool bRet = sal_False;
if ( rData->aKey.getLength() )
{
@@ -499,6 +503,8 @@ Reference < XInputStream > ZipFile::createUnbufferedStream(
sal_Bool bIsEncrypted,
::rtl::OUString aMediaType )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
}
@@ -514,6 +520,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
SotMutexHolderRef aMutexHolder )
throw(IOException, ZipException, RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if ( rEntry.nOffset <= 0 )
readLOC( rEntry );
@@ -543,6 +551,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
ZipException,
RuntimeException )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if ( rEntry.nOffset <= 0 )
readLOC( rEntry );
@@ -579,6 +589,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
SotMutexHolderRef aMutexHolder )
throw(IOException, ZipException, RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if ( rEntry.nOffset <= 0 )
readLOC( rEntry );
@@ -595,6 +607,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
ZipException,
RuntimeException )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
if ( rData.isEmpty() )
throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
@@ -607,6 +621,8 @@ Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
throw(IOException, ZipException, RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
sal_Int32 nTestSig, nTime, nCRC, nSize, nCompressedSize;
sal_Int16 nVersion, nFlag, nHow, nPathLen, nExtraLen;
sal_Int32 nPos = -rEntry.nOffset;
@@ -660,6 +676,7 @@ sal_Bool ZipFile::readLOC( ZipEntry &rEntry )
sal_Int32 ZipFile::findEND( )
throw(IOException, ZipException, RuntimeException)
{
+ // this method is called in constructor only, no need for mutex
sal_Int32 nLength, nPos, nEnd;
Sequence < sal_Int8 > aBuffer;
try
@@ -701,6 +718,7 @@ sal_Int32 ZipFile::findEND( )
sal_Int32 ZipFile::readCEN()
throw(IOException, ZipException, RuntimeException)
{
+ // this method is called in constructor only, no need for mutex
sal_Int32 nCenLen, nCenPos = -1, nCenOff, nEndPos, nLocPos;
sal_uInt16 nCount, nTotal;
@@ -807,6 +825,8 @@ sal_Int32 ZipFile::readCEN()
sal_Int32 ZipFile::recover()
throw(IOException, ZipException, RuntimeException)
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
sal_Int32 nLength;
Sequence < sal_Int8 > aBuffer;
Sequence < sal_Int32 > aHeaderOffsets;
@@ -974,6 +994,8 @@ sal_Int32 ZipFile::recover()
sal_Bool ZipFile::checkSizeAndCRC( const ZipEntry& aEntry )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
sal_Int32 nSize = 0, nCRC = 0;
if( aEntry.nMethod == STORED )
@@ -985,6 +1007,8 @@ sal_Bool ZipFile::checkSizeAndCRC( const ZipEntry& aEntry )
sal_Int32 ZipFile::getCRC( sal_Int32 nOffset, sal_Int32 nSize )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
Sequence < sal_Int8 > aBuffer;
CRC32 aCRC;
sal_Int32 nBlockSize = ::std::min( nSize, static_cast< sal_Int32 >( 32000 ) );
@@ -1002,6 +1026,8 @@ sal_Int32 ZipFile::getCRC( sal_Int32 nOffset, sal_Int32 nSize )
void ZipFile::getSizeAndCRC( sal_Int32 nOffset, sal_Int32 nCompressedSize, sal_Int32 *nSize, sal_Int32 *nCRC )
{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
Sequence < sal_Int8 > aBuffer;
CRC32 aCRC;
sal_Int32 nRealSize = 0;