Kaydet (Commit) def6f7f7 authored tarafından Mohammed Abdul Azeem's avatar Mohammed Abdul Azeem Kaydeden (comit) Michael Meeks

tdf#108835 Fixed writer crash on adding Autocorrect Entry:

ZipPackageStream::saveChild seeks and reads on the same
stream, so it cannot be done parallely. Also, read on
BufferedStream tries to aquire the same mutes, which is
already aquired by the calling method resulting in
deadlock. Using UnbufferedStream here should solve both.

Change-Id: I25b7ca2ff3c31125cf107fe404f9af66435bec7d
Reviewed-on: https://gerrit.libreoffice.org/40160Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 887e9829
......@@ -71,6 +71,7 @@ class ZipFile
const ::rtl::Reference < EncryptionData > &rData,
sal_Int8 nStreamMode,
bool bDecrypt,
const bool bUseBufferedStream = true,
const OUString& aMediaType = OUString() );
bool hasValidPassword ( ZipEntry & rEntry, const rtl::Reference < EncryptionData > &rData );
......@@ -108,7 +109,8 @@ public:
ZipEntry& rEntry,
const ::rtl::Reference < EncryptionData > &rData,
bool bDecrypt,
const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder );
const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder,
const bool bUseBufferedStream = true );
static css::uno::Reference< css::xml::crypto::XDigestContext > StaticGetDigestContextForChecksum(
const css::uno::Reference< css::uno::XComponentContext >& xArgContext,
......
......@@ -74,7 +74,7 @@ private:
/// Check that m_xStream implements io::XSeekable and return it
css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream();
/// @throws css::uno::RuntimeException
css::uno::Reference< css::io::XInputStream > SAL_CALL getRawData();
css::uno::Reference< css::io::XInputStream > SAL_CALL getRawData( const bool bUseBufferedStream = true );
public:
bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
......
......@@ -609,6 +609,7 @@ uno::Reference< XInputStream > ZipFile::createStreamForZipEntry(
const ::rtl::Reference< EncryptionData > &rData,
sal_Int8 nStreamMode,
bool bIsEncrypted,
const bool bUseBufferedStream,
const OUString& aMediaType )
{
::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
......@@ -616,6 +617,9 @@ uno::Reference< XInputStream > ZipFile::createStreamForZipEntry(
rtl::Reference< XUnbufferedStream > xSrcStream = new XUnbufferedStream(
m_xContext, aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode);
if (!bUseBufferedStream)
return xSrcStream.get();
uno::Reference<io::XInputStream> xBufStream;
static const sal_Int32 nThreadingThreshold = 10000;
......@@ -698,14 +702,15 @@ uno::Reference< XInputStream > ZipFile::getDataStream( ZipEntry& rEntry,
uno::Reference< XInputStream > ZipFile::getRawData( ZipEntry& rEntry,
const ::rtl::Reference< EncryptionData >& rData,
bool bIsEncrypted,
const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder )
const rtl::Reference<comphelper::RefCountedMutex>& aMutexHolder,
const bool bUseBufferedStream )
{
::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
if ( rEntry.nOffset <= 0 )
readLOC( rEntry );
return createStreamForZipEntry ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
return createStreamForZipEntry ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted, bUseBufferedStream );
}
uno::Reference< XInputStream > ZipFile::getWrappedRawStream(
......@@ -722,7 +727,7 @@ uno::Reference< XInputStream > ZipFile::getWrappedRawStream(
if ( rEntry.nOffset <= 0 )
readLOC( rEntry );
return createStreamForZipEntry ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, true, aMediaType );
return createStreamForZipEntry ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, true, true, aMediaType );
}
bool ZipFile::readLOC( ZipEntry &rEntry )
......
......@@ -572,7 +572,7 @@ bool ZipPackageStream::saveChild(
if ( !bUseNonSeekableAccess )
{
xStream = getRawData();
xStream = getRawData( false );
if ( !xStream.is() )
{
......@@ -708,7 +708,7 @@ bool ZipPackageStream::saveChild(
// to get a new version of it as we can't seek backwards.
if ( IsPackageMember() )
{
xStream = getRawData();
xStream = getRawData( false );
if ( !xStream.is() )
{
// Make sure that we actually _got_ a new one !
......@@ -937,13 +937,13 @@ void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInput
m_nStreamMode = PACKAGE_STREAM_DETECT;
}
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData()
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData( const bool bUseBufferedStream )
{
try
{
if ( IsPackageMember() )
{
return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef(), bUseBufferedStream );
}
else if ( GetOwnSeekStream().is() )
{
......
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