tdf#167006: OWriteStream needs to implement comphelper::ByteReader

A crash seen with this call stack:

  package2.dll!ByteGrabber::ByteGrabber(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & xIstream) Line 44++
  package2.dll!ZipFile::ZipFile(rtl::Reference<comphelper::RefCountedMutex> aMutexHolder, const com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & xInput, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> xContext, bool bInitialise, bool bForceRecovery, ZipFile::Checks checks) Line 92++
  package2.dll!std::_Construct_in_place<ZipFile,rtl::Reference<comphelper::RefCountedMutex> &,com::sun::star::uno::Reference<com::sun::star::io::XInputStream> &,com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> &,bool,bool,enum ZipFile::Checks>(ZipFile & _Obj, rtl::Reference<comphelper::RefCountedMutex> & <_Args_0>, com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & <_Args_1>, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & <_Args_2>, bool && <_Args_3>, bool && <_Args_4>, ZipFile::Checks && <_Args_5>) Line 476++
  package2.dll!std::_Optional_construct_base<ZipFile>::_Construct<rtl::Reference<comphelper::RefCountedMutex> &,com::sun::star::uno::Reference<com::sun::star::io::XInputStream> &,com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> &,bool,bool,enum ZipFile::Checks>(rtl::Reference<comphelper::RefCountedMutex> & <_Args_0>, com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & <_Args_1>, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & <_Args_2>, bool && <_Args_3>, bool && <_Args_4>, ZipFile::Checks && <_Args_5>) Line 157++
  package2.dll!std::optional<ZipFile>::emplace<rtl::Reference<comphelper::RefCountedMutex> &,com::sun::star::uno::Reference<com::sun::star::io::XInputStream> &,com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> &,bool,bool,enum ZipFile::Checks>(rtl::Reference<comphelper::RefCountedMutex> & <_Args_0>, com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & <_Args_1>, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & <_Args_2>, bool && <_Args_3>, bool && <_Args_4>, ZipFile::Checks && <_Args_5>) Line 355++
  package2.dll!OZipFileAccess::initialize(const com::sun::star::uno::Sequence<com::sun::star::uno::Any> & aArguments) Line 243++
  cppuhelper3MSC.dll!cppuhelper::ServiceManager::Data::Implementation::doCreateInstanceWithArguments(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & context, const com::sun::star::uno::Sequence<com::sun::star::uno::Any> & arguments) Line 728++
  cppuhelper3MSC.dll!cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & context, bool singletonRequest, const com::sun::star::uno::Sequence<com::sun::star::uno::Any> & arguments) Line 690++
  cppuhelper3MSC.dll!cppuhelper::ServiceManager::createInstanceWithArgumentsAndContext(const rtl::OUString & ServiceSpecifier, const com::sun::star::uno::Sequence<com::sun::star::uno::Any> & Arguments, const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & Context) Line 1014++
  writerperfectlo.dll!writerperfect::WPXSvInputStream::isZip() Line 705++
  writerperfectlo.dll!writerperfect::WPXSvInputStream::isStructured() Line 489++
  mwaw.dll!MWAWInputStream::isStructured() Line 841++
  mwaw.dll!MWAWInputStream::unsplitInternalMergeStream() Line 574++
  mwaw.dll!MWAWInputStream::MWAWInputStream(librevenge::RVNGInputStream * inp, bool inverted, bool checkCompression) Line 79++
  mwaw.dll!MWAWDocument::isFileFormatSupported(librevenge::RVNGInputStream * input, MWAWDocument::Type & type, MWAWDocument::Kind & kind) Line 143++
  wpftwriterlo.dll!MWAWImportFilter::doDetectFormat(librevenge::RVNGInputStream & rInput, rtl::OUString & rTypeName) Line 50++
  wpftwriterlo.dll!writerperfect::detail::ImportFilterImpl<OdtGenerator>::detect(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> & Descriptor) Line 136++
  filterconfiglo.dll!filter::config::TypeDetection::impl_askDetectService(const rtl::OUString & sDetectService, utl::MediaDescriptor & rDescriptor) Line 1136++
  filterconfiglo.dll!filter::config::TypeDetection::impl_detectTypeFlatAndDeep(utl::MediaDescriptor & rDescriptor, const std::vector<filter::config::FlatDetectionInfo,std::allocator<filter::config::FlatDetectionInfo>> & lFlatTypes, bool bAllowDeep, rtl::OUString & rLastChance) Line 1041++
  filterconfiglo.dll!filter::config::TypeDetection::queryTypeByDescriptor(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> & lDescriptor, unsigned char bAllowDeep) Line 436++
  emboleobj.dll!OwnView_Impl::GetFilterNameFromExtentionAndInStream(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> & xContext, std::basic_string_view<char16_t,std::char_traits<char16_t>> aNameWithExtention, const com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & xInputStream) Line 207++
  emboleobj.dll!OleEmbeddedObject::TryToConvertToOOo(const com::sun::star::uno::Reference<com::sun::star::io::XStream> & xStream) Line 265++
  emboleobj.dll!OleEmbeddedObject::doVerb(long nVerbID) Line 908++

where ByteGrabber ctor takes an instance of OWriteStream.

Change-Id: Ic60fa1aa3e79848256273c761d132d6bb33c179a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186479
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski
2025-06-14 14:12:25 +02:00
parent e931c4e939
commit 587e46e7bc
4 changed files with 31 additions and 1 deletions
+19
View File
@@ -1898,6 +1898,25 @@ sal_Int32 SAL_CALL OWriteStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData
return m_xInStream->readSomeBytes( aData, nMaxBytesToRead );
}
sal_Int32 OWriteStream::readSomeBytes(sal_Int8* pData, sal_Int32 nBytesToRead)
{
osl::MutexGuard aGuard(m_xSharedMutex->GetMutex());
CheckInitOnDemand();
if (!m_xInStream.is())
throw io::NotConnectedException();
if (auto pByteReader = dynamic_cast<comphelper::ByteReader*>(m_xInStream.get()))
return pByteReader->readSomeBytes(pData, nBytesToRead);
uno::Sequence<sal_Int8> aData;
sal_Int32 nRead = m_xInStream->readSomeBytes(aData, nBytesToRead);
std::copy_n(aData.getConstArray(), nRead, pData);
return nRead;
}
void SAL_CALL OWriteStream::skipBytes( sal_Int32 nBytesToSkip )
{
::osl::MutexGuard aGuard( m_xSharedMutex->GetMutex() );
+4 -1
View File
@@ -232,6 +232,7 @@ class OWriteStream : public css::lang::XTypeProvider
, public css::embed::XTransactionBroadcaster
, public css::beans::XPropertySet
, public ::cppu::OWeakObject
, public comphelper::ByteReader
, public comphelper::ByteWriter
{
friend struct OWriteStream_Impl;
@@ -348,9 +349,11 @@ public:
virtual void SAL_CALL removeTransactionListener(
const css::uno::Reference< css::embed::XTransactionListener >& aListener ) override;
// comphelper::ByteReader
virtual sal_Int32 readSomeBytes(sal_Int8* aData, sal_Int32 nBytesToRead) override;
// comphelper::ByteWriter
virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
};
#endif
Binary file not shown.
+8
View File
@@ -1267,6 +1267,14 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf71583)
}
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf167006)
{
createSwDoc("embeddedPPTX.docx");
selectShape(1);
// attempt to edit the OLE object. This must not crash.
getSwDocShell()->GetWrtShell()->LaunchOLEObj();
}
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();