From 8556df333ee23daf918ec50ce675369e3466380f Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Tue, 20 Mar 2018 22:57:17 -0400 Subject: oox: don't segfault when failing to open a custom fragment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie05d1feea2e930b117b3754c6e0db86bdb85bc61 Reviewed-on: https://gerrit.libreoffice.org/51681 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara (cherry picked from commit f82888653c853f236ab0035bb578a7129ec72fa5) Reviewed-on: https://gerrit.libreoffice.org/52228 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky --- oox/source/core/xmlfilterbase.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'oox/source') diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 873991a8f998..39a5858ae642 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -1119,13 +1119,16 @@ void XmlFilterBase::exportCustomFragments() addRelation(customFragmentTypes[j], customFragmentTargets[j]); const OUString aFilename = customFragmentTargets[j]; Reference xOutStream = openOutputStream(aFilename); - xOutStream->writeBytes(customFragments[j]); - uno::Reference xProps(xOutStream, uno::UNO_QUERY); - if (xProps.is()) + if (xOutStream.is()) { - const OUString aType = comphelper::OFOPXMLHelper::GetContentTypeByName(aContentTypes, aFilename); - const OUString aContentType = (aType.getLength() ? aType : OUString("application/octet-stream")); - xProps->setPropertyValue("MediaType", uno::makeAny(aContentType)); + xOutStream->writeBytes(customFragments[j]); + uno::Reference xProps(xOutStream, uno::UNO_QUERY); + if (xProps.is()) + { + const OUString aType = comphelper::OFOPXMLHelper::GetContentTypeByName(aContentTypes, aFilename); + const OUString aContentType = (aType.getLength() ? aType : OUString("application/octet-stream")); + xProps->setPropertyValue("MediaType", uno::makeAny(aContentType)); + } } } } -- cgit