diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-10-11 10:45:40 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-10-12 09:52:15 +0200 |
commit | 06423ddc61a378894c91a6a23fb31afb1701d8f2 (patch) | |
tree | deb6ad0b2212885c263b58849652e87cb2e0cb06 | |
parent | 56b8703d6f759326f7ac1a84ca0e6d1c9b40aad7 (diff) |
crashtesting: exception during dtor
Change-Id: I9874778ba79540cfde32bf59c3a63ebb72889dc7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141215
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/sax/fshelper.hxx | 3 | ||||
-rw-r--r-- | oox/source/core/xmlfilterbase.cxx | 6 | ||||
-rw-r--r-- | oox/source/export/chartexport.cxx | 3 | ||||
-rw-r--r-- | sax/source/tools/fshelper.cxx | 20 | ||||
-rw-r--r-- | sc/source/filter/excel/xestream.cxx | 6 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-epptooxml.cxx | 23 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 20 |
7 files changed, 79 insertions, 2 deletions
diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx index 115a3f912ca5..2d01066a1453 100644 --- a/include/sax/fshelper.hxx +++ b/include/sax/fshelper.hxx @@ -50,6 +50,9 @@ public: ~FastSerializerHelper(); + void startDocument(); + void endDocument(); + /// Start an element. After the first argument there can be a number of (attribute, value) pairs. template<typename... Args> void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, Args &&... args) diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index e0e8b099ea5e..c2911a756047 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -697,6 +697,8 @@ writeCoreProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties } pCoreProps->endElementNS( XML_cp, XML_coreProperties ); + + pCoreProps->endDocument(); } static void @@ -819,6 +821,8 @@ writeAppProperties( XmlFilterBase& rSelf, const Reference< XDocumentProperties > } pAppProps->endElement( XML_Properties ); + + pAppProps->endDocument(); } static void @@ -937,6 +941,8 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie ++nIndex; } pAppProps->endElement( XML_Properties ); + + pAppProps->endDocument(); } void XmlFilterBase::exportDocumentProperties( const Reference< XDocumentProperties >& xProperties, bool bSecurityOptOpenReadOnly ) diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 6bdede718f05..b60e84590ae9 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -874,6 +874,8 @@ void ChartExport::WriteChartObj( const Reference< XShape >& xShape, sal_Int32 nI SetFS( pChart ); ExportContent(); + SetFS( pFS ); + pChart->endDocument(); } void ChartExport::InitRangeSegmentationProperties( const Reference< chart2::XChartDocument > & xChartDoc ) @@ -1115,6 +1117,7 @@ void ChartExport::exportAdditionalShapes( const Reference< css::chart::XChartDoc pDrawing->endElement(FSNS(XML_cdr, XML_relSizeAnchor)); } pDrawing->endElement(FSNS(XML_c, XML_userShapes)); + pDrawing->endDocument(); } } catch (const uno::Exception&) diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx index 7cbd3c36abc1..fbf7f0672709 100644 --- a/sax/source/tools/fshelper.cxx +++ b/sax/source/tools/fshelper.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/log.hxx> #include <sax/fshelper.hxx> #include "fastserializer.hxx" @@ -29,12 +30,27 @@ FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& mpSerializer(new FastSaxSerializer(xOutputStream)) { if( bWriteHeader ) - mpSerializer->startDocument(); + startDocument(); +} + +void FastSerializerHelper::startDocument() +{ + mpSerializer->startDocument(); +} + +void FastSerializerHelper::endDocument() +{ + std::unique_ptr<FastSaxSerializer> xSerializer(std::move(mpSerializer)); + xSerializer->endDocument(); } FastSerializerHelper::~FastSerializerHelper() { - mpSerializer->endDocument(); + if (mpSerializer) + { + assert(false && "call endDocument explicitly before dtor to avoid potential exceptions during dtor"); + endDocument(); + } } void FastSerializerHelper::startElement(sal_Int32 elementTokenId) diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index b94959292891..04cb7ad23ec7 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -1113,6 +1113,12 @@ bool XclExpXmlStream::exportDocument() PopStream(); // Free all FSHelperPtr, to flush data before committing storage + for (auto& entry : maOpenedStreamMap) + { + if (!entry.second.second) + continue; + entry.second.second->endDocument(); + } maOpenedStreamMap.clear(); commitStorage(); diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index cddb923f7e9e..9a6bd502958c 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -499,8 +499,15 @@ bool PowerPointExport::exportDocument() WriteModifyVerifier(); mPresentationFS->endElementNS(XML_p, XML_presentation); + mPresentationFS->endDocument(); mPresentationFS.reset(); // Free all FSHelperPtr, to flush data before committing storage + for (auto& serializer : mpSlidesFSArray) + { + if (!serializer) + continue; + serializer->endDocument(); + } mpSlidesFSArray.clear(); commitStorage(); @@ -1087,6 +1094,8 @@ void PowerPointExport::WriteAuthors() } pFS->endElementNS(XML_p, XML_cmAuthorLst); + + pFS->endDocument(); } sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex(const OUString& sAuthor, sal_Int32& nLastIndex) @@ -1178,6 +1187,8 @@ void PowerPointExport::WritePresentationProps() pFS->endElementNS(XML_p, XML_showPr); pFS->endElementNS(XML_p, XML_presentationPr); + + pFS->endDocument(); } bool PowerPointExport::WriteComments(sal_uInt32 nPageNum) @@ -1229,6 +1240,8 @@ bool PowerPointExport::WriteComments(sal_uInt32 nPageNum) pFS->endElementNS(XML_p, XML_cmLst); + pFS->endDocument(); + return true; } } @@ -1454,6 +1467,8 @@ void PowerPointExport::ImplWriteNotes(sal_uInt32 nPageNum) u"../notesMasters/notesMaster1.xml"); SAL_INFO("sd.eppt", "-----------------"); + + pFS->endDocument(); } void PowerPointExport::AddLayoutIdAndRelation(const FSHelperPtr& pFS, sal_Int32 nLayoutFileId) @@ -1554,6 +1569,8 @@ void PowerPointExport::ImplWriteSlideMaster(sal_uInt32 nPageNum, Reference< XPro pFS->endElementNS(XML_p, XML_sldMaster); SAL_INFO("sd.eppt", "----------------"); + + pFS->endDocument(); } sal_Int32 PowerPointExport::GetLayoutFileId(sal_Int32 nOffset, sal_uInt32 nMasterNum) @@ -1623,6 +1640,8 @@ void PowerPointExport::ImplWritePPTXLayout(sal_Int32 nOffset, sal_uInt32 nMaster mnLayoutFileIdMax ++; xDrawPages->remove(xSlide); + + pFS->endDocument(); } void PowerPointExport::WriteShapeTree(const FSHelperPtr& pFS, PageType ePageType, bool bMaster) @@ -2303,6 +2322,8 @@ void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, svx::Theme* pTheme) pFS->endElementNS(XML_a, XML_themeElements); pFS->endElementNS(XML_a, XML_theme); + + pFS->endDocument(); } bool PowerPointExport::ImplCreateDocument() @@ -2381,6 +2402,8 @@ void PowerPointExport::WriteNotesMaster() pFS->endElementNS(XML_p, XML_notesMaster); SAL_INFO("sd.eppt", "----------------"); + + pFS->endDocument(); } void PowerPointExport::embedEffectAudio(const FSHelperPtr& pFS, const OUString& sUrl, OUString& sRelId, OUString& sName) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index ba66748c7ba3..7b00df3b65ac 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -401,6 +401,7 @@ OString DocxExport::OutputChart( uno::Reference< frame::XModel > const & xModel, #else (void)xModel; #endif + pChartFS->endDocument(); return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 ); } @@ -497,6 +498,8 @@ std::pair<OString, OString> DocxExport::WriteActiveXObject(const uno::Reference< sXMLFileName.subView(sBinaryFileName.indexOf("/") + 1)), RTL_TEXTENCODING_UTF8); + pActiveXFS->endDocument(); + return std::pair<OString, OString>(sXMLId, sName); } @@ -673,6 +676,8 @@ void DocxExport::InitStyles() // switch the serializer back m_pAttrOutput->SetSerializer( m_pDocumentFS ); + + pStylesFS->endDocument(); } void DocxExport::WriteFootnotesEndnotes() @@ -702,6 +707,8 @@ void DocxExport::WriteFootnotesEndnotes() m_pVMLExport->SetFS(m_pDocumentFS); m_pSdrExport->setSerializer( m_pDocumentFS ); m_pAttrOutput->SetSerializer( m_pDocumentFS ); + + pFootnotesFS->endDocument(); } if ( !m_pAttrOutput->HasEndnotes() ) @@ -730,6 +737,8 @@ void DocxExport::WriteFootnotesEndnotes() m_pVMLExport->SetFS(m_pDocumentFS); m_pSdrExport->setSerializer( m_pDocumentFS ); m_pAttrOutput->SetSerializer( m_pDocumentFS ); + + pEndnotesFS->endDocument(); } void DocxExport::WritePostitFields() @@ -750,6 +759,7 @@ void DocxExport::WritePostitFields() const auto eHasResolved = m_pAttrOutput->WritePostitFields(); m_pAttrOutput->SetSerializer( m_pDocumentFS ); pPostitFS->endElementNS( XML_w, XML_comments ); + pPostitFS->endDocument(); if (eHasResolved != DocxAttributeOutput::hasResolved::yes) return; @@ -770,6 +780,7 @@ void DocxExport::WritePostitFields() m_pAttrOutput->WritePostItFieldsResolved(); m_pAttrOutput->SetSerializer(m_pDocumentFS); pPostitFS->endElementNS(XML_w15, XML_commentsEx); + pPostitFS->endDocument(); } void DocxExport::WriteNumbering() @@ -808,6 +819,8 @@ void DocxExport::WriteNumbering() // switch the serializer back m_pDrawingML->SetFS( m_pDocumentFS ); m_pAttrOutput->SetSerializer( m_pDocumentFS ); + + pNumberingFS->endDocument(); } void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const char* pType ) @@ -880,6 +893,8 @@ void DocxExport::WriteHeaderFooter( const SwFormat* pFormat, bool bHeader, const m_pDocumentFS->singleElementNS( XML_w, nReference, FSNS( XML_w, XML_type ), pType, FSNS( XML_r, XML_id ), aRelId ); + + pFS->endDocument(); } void DocxExport::WriteFonts() @@ -906,6 +921,8 @@ void DocxExport::WriteFonts() m_pAttrOutput->SetSerializer( m_pDocumentFS ); pFS->endElementNS( XML_w, XML_fonts ); + + pFS->endDocument(); } void DocxExport::WriteProperties( ) @@ -1431,6 +1448,8 @@ void DocxExport::WriteSettings() // finish settings.xml pFS->endElementNS( XML_w, XML_settings ); + + pFS->endDocument(); } void DocxExport::WriteTheme() @@ -2102,6 +2121,7 @@ DocxExport::DocxExport(DocxExportFilter& rFilter, SwDoc& rDocument, DocxExport::~DocxExport() { + m_pDocumentFS->endDocument(); } DocxSettingsData::DocxSettingsData() |