[Libreoffice-commits] core.git: 5 commits - sax/source sw/qa writerfilter/source writerperfect/source
Michael Stahl
mstahl at redhat.com
Thu Jan 22 05:04:32 PST 2015
dev/null |binary
sax/source/fastparser/fastparser.cxx | 22 +++--
sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 5 -
sw/qa/extras/ooxmlimport/data/math-malformed_xml.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 40 ++++++++++
writerfilter/source/filter/ImportFilter.cxx | 72 +++++++++++++++++-
writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 25 ++++++
writerperfect/source/common/WPXSvInputStream.cxx | 2
8 files changed, 148 insertions(+), 18 deletions(-)
New commits:
commit ebf767eeb2a169ba533e1b2ffccf16f41d95df35
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 22 12:50:07 2015 +0100
writerfilter: DOCX import: better error handling than "catch (...) {}"
If there is a SAXParseException, OOXMLDocumentImpl::resolve() should not
ignore it, because if it occurs in a substream some end tag handlers may
not have been run and the DomainMapper may be in an inconsistent state,
so continuing to parse the outer document is probably not a good idea.
Also add some exception mangling so sfx2 can present a useful error
dialog.
Change-Id: I169ba6db25f2ae264af08a64edf76a6bf6757f85
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index 6d7a87a..6a76477 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -266,11 +266,6 @@ DECLARE_OOXMLEXPORT_TEST(testMathLim, "math-lim.docx")
CHECK_FORMULA( "lim from {x \xe2\x86\x92 1} {x}", getFormula( getRun( getParagraph( 1 ), 1 )));
}
-DECLARE_OOXMLEXPORT_TEST(testMathMalformedXml, "math-malformed_xml.docx")
-{
- CPPUNIT_ASSERT_EQUAL( 0, getLength());
-}
-
DECLARE_OOXMLEXPORT_TEST(testMathMatrix, "math-matrix.docx")
{
CHECK_FORMULA( "left [matrix {1 # 2 ## 3 # 4} right ]", getFormula( getRun( getParagraph( 1 ), 1 )));
diff --git a/sw/qa/extras/ooxmlexport/data/math-malformed_xml.docx b/sw/qa/extras/ooxmlimport/data/math-malformed_xml.docx
similarity index 100%
rename from sw/qa/extras/ooxmlexport/data/math-malformed_xml.docx
rename to sw/qa/extras/ooxmlimport/data/math-malformed_xml.docx
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 5202899..a6fb079 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -89,6 +89,46 @@ public:
}
};
+class FailTest : public Test
+{
+public:
+ // UGLY: hacky manual override of MacrosTest::loadFromDesktop
+ void executeImportTest(const char* filename)
+ {
+ header();
+ preTest(filename);
+ {
+ if (mxComponent.is())
+ mxComponent->dispose();
+ std::cout << filename << ",";
+ mnStartTime = osl_getGlobalTimer();
+ {
+ OUString aURL(getURLFromSrc(mpTestDocumentPath) + OUString::createFromAscii(filename));
+ CPPUNIT_ASSERT_MESSAGE("no desktop", mxDesktop.is());
+ uno::Reference<frame::XComponentLoader> xLoader = uno::Reference<frame::XComponentLoader>(mxDesktop, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_MESSAGE("no loader", xLoader.is());
+ uno::Sequence<beans::PropertyValue> args(1);
+ args[0].Name = "DocumentService";
+ args[0].Handle = -1;
+ args[0].Value <<= OUString("com.sun.star.text.TextDocument");
+ args[0].State = beans::PropertyState_DIRECT_VALUE;
+
+ uno::Reference<lang::XComponent> xComponent = xLoader->loadComponentFromURL(aURL, OUString("_default"), 0, args);
+ OUString sMessage = "loading succeeded: " + aURL;
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sMessage, RTL_TEXTENCODING_UTF8).getStr(), !xComponent.is());
+ }
+ }
+ postTest(filename);
+ verify();
+ finish();
+ }
+};
+
+DECLARE_SW_IMPORT_TEST(testMathMalformedXml, "math-malformed_xml.docx", FailTest)
+{
+ CPPUNIT_ASSERT(!mxComponent.is());
+}
+
DECLARE_OOXMLIMPORT_TEST(testN751054, "n751054.docx")
{
text::TextContentAnchorType eValue = getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType");
diff --git a/writerfilter/source/filter/ImportFilter.cxx b/writerfilter/source/filter/ImportFilter.cxx
index d14ce08..f67a7ff 100644
--- a/writerfilter/source/filter/ImportFilter.cxx
+++ b/writerfilter/source/filter/ImportFilter.cxx
@@ -23,6 +23,9 @@
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/io/WrongFormatException.hpp>
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
#include <unotools/mediadescriptor.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <oox/core/filterdetect.hxx>
@@ -37,9 +40,48 @@
#include <oox/ole/olestorage.hxx>
#include <oox/ole/vbaproject.hxx>
#include <oox/helper/graphichelper.hxx>
+
using namespace ::com::sun::star;
+static OUString lcl_GetExceptionMessageRec(xml::sax::SAXException const& e);
+
+static OUString lcl_GetExceptionMessage(xml::sax::SAXException const& e)
+{
+ OUString const thisMessage("SAXParseException: "
+ "\"" + e.Message + "\"");
+ OUString const restMessage(lcl_GetExceptionMessageRec(e));
+ return restMessage + "\n" + thisMessage;
+}
+static OUString lcl_GetExceptionMessage(xml::sax::SAXParseException const& e)
+{
+ OUString const thisMessage("SAXParseException: "
+ "\"" + e.Message + "\" "
+ + "stream \"" + e.SystemId + "\""
+ + ", Line " + OUString::number(e.LineNumber)
+ + ", Column " + OUString::number(e.ColumnNumber));
+ OUString const restMessage(lcl_GetExceptionMessageRec(e));
+ return restMessage + "\n" + thisMessage;
+}
+static OUString lcl_GetExceptionMessageRec(xml::sax::SAXException const& e)
+{
+ xml::sax::SAXParseException saxpe;
+ if (e.WrappedException >>= saxpe)
+ {
+ return lcl_GetExceptionMessage(saxpe);
+ }
+ xml::sax::SAXException saxe;
+ if (e.WrappedException >>= saxe)
+ {
+ return lcl_GetExceptionMessage(saxe);
+ }
+ uno::Exception ue;
+ if (e.WrappedException >>= ue)
+ {
+ return ue.Message;
+ }
+ return OUString();
+}
sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
throw (uno::RuntimeException, std::exception)
@@ -93,7 +135,35 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes
(xDrawings->getDrawPage(), uno::UNO_SET_THROW);
pDocument->setDrawPage(xDrawPage);
- pDocument->resolve(*pStream);
+ try
+ {
+ pDocument->resolve(*pStream);
+ }
+ catch (xml::sax::SAXParseException const& e)
+ {
+ // note: SfxObjectShell checks for WrongFormatException
+ io::WrongFormatException wfe(lcl_GetExceptionMessage(e));
+ throw lang::WrappedTargetRuntimeException("",
+ static_cast<OWeakObject*>(this), uno::makeAny(wfe));
+ }
+ catch (xml::sax::SAXException const& e)
+ {
+ // note: SfxObjectShell checks for WrongFormatException
+ io::WrongFormatException wfe(lcl_GetExceptionMessage(e));
+ throw lang::WrappedTargetRuntimeException("",
+ static_cast<OWeakObject*>(this), uno::makeAny(wfe));
+ }
+ catch (uno::RuntimeException const& e)
+ {
+ throw;
+ }
+ catch (uno::Exception const& e)
+ {
+ SAL_WARN("writerfilter", "WriterFilter::filter(): "
+ "failed with exception " << e.Message);
+ throw lang::WrappedTargetRuntimeException("",
+ static_cast<OWeakObject*>(this), uno::makeAny(e));
+ }
// Adding some properties to the document's grab bag for interoperability purposes:
comphelper::SequenceAsHashMap aGrabBagProperties;
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 7f3508e..0481bd1 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/xml/sax/SAXException.hpp>
#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
@@ -500,7 +501,28 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
{
xParser->parseStream(aParserInput);
}
- catch (...) {
+ catch (xml::sax::SAXException const&)
+ {
+ // don't swallow these - handlers may not have been executed,
+ // and the domain mapper is likely in an inconsistent state
+ throw;
+ }
+ catch (uno::RuntimeException const& e)
+ {
+ throw;
+ }
+ // note: cannot throw anything other than SAXException out of here?
+ catch (uno::Exception const& e)
+ {
+ SAL_WARN("writerfilter.ooxml",
+ "OOXMLDocumentImpl::resolve(): exception: " << e.Message);
+ throw lang::WrappedTargetRuntimeException("", nullptr,
+ uno::makeAny(e));
+ }
+ catch (...)
+ {
+ SAL_WARN("writerfilter.ooxml",
+ "OOXMLDocumentImpl::resolve(): non-UNO exception");
}
}
commit 825e4995220209362c13ed5f07c98e43a5f456de
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 22 12:14:34 2015 +0100
writerfilter: set the SystemId to get stream name in SAXExceptions
Change-Id: I9891269a765ace15497a3cd3b1729be941bc3c1b
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 80c508ab..7f3508e 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -494,6 +494,7 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
xParser->setTokenHandler( xTokenHandler );
xml::sax::InputSource aParserInput;
+ aParserInput.sSystemId = mpStream->getTarget();
aParserInput.aInputStream = mpStream->getDocumentStream();
try
{
commit c71f888590a4864de96290c06e952bd0a40e7ee7
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 22 12:12:05 2015 +0100
sax: fastparser: use cppu::getCaughtException() to avoid sliced exceptions
Change-Id: I1cd932ae520ba20eff8ef447614e91e1cc2032f8
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 0f76a30..82a2856 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
#include <cppuhelper/supportsservice.hxx>
+#include <cppuhelper/exc_hlp.hxx>
#include <osl/conditn.hxx>
#include <osl/diagnose.h>
#include <rtl/ref.hxx>
@@ -169,7 +170,7 @@ struct Entity : public ParserData
// resource leaks), therefore any exception thrown by a UNO callback
// must be saved somewhere until the C-XmlParser is stopped.
::com::sun::star::uno::Any maSavedException;
- void saveException( const Exception &e );
+ void saveException( const Any & e );
void throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumentLocator,
bool mbDuringParse );
@@ -457,7 +458,7 @@ void Entity::startElement( Event *pEvent )
}
catch (const Exception& e)
{
- saveException( e );
+ saveException( ::cppu::getCaughtException() );
}
}
@@ -476,7 +477,7 @@ void Entity::characters( const OUString& sChars )
}
catch (const Exception& e)
{
- saveException( e );
+ saveException( ::cppu::getCaughtException() );
}
}
@@ -500,7 +501,7 @@ void Entity::endElement()
}
catch (const Exception& e)
{
- saveException( e );
+ saveException( ::cppu::getCaughtException() );
}
maContextStack.pop();
}
@@ -591,13 +592,14 @@ void Entity::throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumen
// If multi-threaded, we need to push an EXCEPTION event, at
// which point we transfer ownership of maSavedException to
// the consuming thread.
-void Entity::saveException( const Exception &e )
+void Entity::saveException( const Any & e )
{
// fdo#81214 - allow the parser to run on after an exception,
// unexpectedly some 'startElements' produce an UNO_QUERY_THROW
// for XComponent; and yet expect to continue parsing.
- SAL_WARN("sax", "Unexpected exception from XML parser " << e.Message);
- maSavedException <<= e;
+ SAL_WARN("sax", "Unexpected exception from XML parser "
+ << e.get<Exception>().Message);
+ maSavedException = e;
}
} // namespace
@@ -1134,9 +1136,9 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
else
rEntity.startElement( &rEvent );
}
- catch (const Exception& e)
+ catch (const Exception&)
{
- rEntity.saveException( e );
+ rEntity.saveException( ::cppu::getCaughtException() );
}
}
commit f0d6e0e1e21afd0adf5bd01d771b2d83d8f13a48
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Jan 22 12:11:31 2015 +0100
sax: there is no OUStringBuffer(char) ctor
Change-Id: I1811dead8f104a445bfee9282a60ecedeca872ed
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index de5a5ea..0f76a30 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -546,7 +546,7 @@ OUString lclGetErrorMessage( xmlParserCtxtPtr ctxt, const OUString& sSystemId, s
pMessage = error->message;
else
pMessage = "unknown error";
- OUStringBuffer aBuffer( '[' );
+ OUStringBuffer aBuffer( "[" );
aBuffer.append( sSystemId );
aBuffer.append( " line " );
aBuffer.append( nLine );
commit d7032371cfc1335073b68b00c0ccab63e244f353
Author: Michael Stahl <mstahl at redhat.com>
Date: Wed Jan 21 14:36:42 2015 +0100
writerperfect: convert assert on invalid input to SAL_WARN
lp502369-3.doc contains several StgEntry that are invalid and have type
0 (STG_EMPTY). Not sure if sot Storage::FillInfoList() should filter
these out.
Change-Id: I493cbb346723a3be4f8bc93de1030e68c1216b50
diff --git a/writerperfect/source/common/WPXSvInputStream.cxx b/writerperfect/source/common/WPXSvInputStream.cxx
index 7bc436f..b1a2a5d 100644
--- a/writerperfect/source/common/WPXSvInputStream.cxx
+++ b/writerperfect/source/common/WPXSvInputStream.cxx
@@ -236,7 +236,7 @@ void OLEStorageImpl::traverse(const SotStorageRef &rStorage, const rtl::OUString
}
else
{
- assert(false);
+ SAL_WARN("writerperfect", "OLEStorageImpl::traverse: invalid storage entry, neither stream nor file");
}
}
}
More information about the Libreoffice-commits
mailing list