[PATCH libreoffice-4-0] fdo#60471: svgio, sax: enable internal entity declarations f...
Michael Stahl (via Code Review)
gerrit at gerrit.libreoffice.org
Wed Feb 13 07:39:51 PST 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/2138
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/38/2138/1
fdo#60471: svgio, sax: enable internal entity declarations for SVG
Change-Id: I147acac61dfe0b626268fe1e600dcf641ca63a0c
(cherry picked from commit fcb1e4d8433b49686cd8e53c699dd5d6503ea314)
---
M sax/source/expatwrap/sax_expat.cxx
M svgio/source/svguno/xsvgparser.cxx
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx
index db17402..6dd88ed 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -24,7 +24,7 @@
#include <osl/diagnose.h>
#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/util/XCloneable.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
#include <com/sun/star/xml/sax/XParser.hpp>
#include <com/sun/star/xml/sax/SAXParseException.hpp>
@@ -32,8 +32,7 @@
#include <cppuhelper/factory.hxx>
#include <cppuhelper/weak.hxx>
-#include <cppuhelper/implbase1.hxx>
-#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
#include <expat.h>
@@ -45,7 +44,6 @@
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::registry;
using namespace ::com::sun::star::xml::sax;
-using namespace ::com::sun::star::util;
using namespace ::com::sun::star::io;
#include "factory.hxx"
@@ -136,11 +134,10 @@
// This class implements the external Parser interface
-class SaxExpatParser :
- public WeakImplHelper2<
- XParser,
- XServiceInfo
- >
+class SaxExpatParser
+ : public WeakImplHelper3< XInitialization
+ , XServiceInfo
+ , XParser >
{
public:
@@ -153,6 +150,10 @@
static Sequence< OUString > getSupportedServiceNames_Static(void) throw ();
public:
+ // ::com::sun::star::lang::XInitialization:
+ virtual void SAL_CALL initialize(Sequence<Any> const& rArguments)
+ throw (RuntimeException, Exception);
+
// The SAX-Parser-Interface
virtual void SAL_CALL parseStream( const InputSource& structSource)
throw ( SAXException,
@@ -222,6 +223,7 @@
public: // module scope
Mutex aMutex;
OUString sCDATA;
+ bool m_bEnableDoS; // fdo#60471 thank you Adobe Illustrator
Reference< XDocumentHandler > rDocumentHandler;
Reference< XExtendedDocumentHandler > rExtendedDocumentHandler;
@@ -257,6 +259,7 @@
public:
SaxExpatParser_Impl()
: sCDATA("CDATA")
+ , m_bEnableDoS(false)
{
}
@@ -452,6 +455,22 @@
delete m_pImpl;
}
+// ::com::sun::star::lang::XInitialization:
+void SAL_CALL
+SaxExpatParser::initialize(Sequence< Any > const& rArguments)
+ throw (RuntimeException, Exception)
+{
+ // possible arguments: a string "DoSmeplease"
+ if (rArguments.getLength())
+ {
+ OUString str;
+ if ((rArguments[0] >>= str) && "DoSmeplease" == str)
+ {
+ MutexGuard guard( m_pImpl->aMutex );
+ m_pImpl->m_bEnableDoS = true;
+ }
+ }
+}
/***************
*
@@ -500,7 +519,10 @@
XML_SetCharacterDataHandler( entity.pParser , call_callbackCharacters );
XML_SetProcessingInstructionHandler(entity.pParser ,
call_callbackProcessingInstruction );
- XML_SetEntityDeclHandler(entity.pParser, call_callbackEntityDecl);
+ if (!m_pImpl->m_bEnableDoS)
+ {
+ XML_SetEntityDeclHandler(entity.pParser, call_callbackEntityDecl);
+ }
XML_SetNotationDeclHandler( entity.pParser, call_callbackNotationDecl );
XML_SetExternalEntityRefHandler( entity.pParser,
call_callbackExternalEntityRef);
diff --git a/svgio/source/svguno/xsvgparser.cxx b/svgio/source/svguno/xsvgparser.cxx
index 26a81c0..1b12d9ad 100644
--- a/svgio/source/svguno/xsvgparser.cxx
+++ b/svgio/source/svguno/xsvgparser.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/graphic/XSvgParser.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
#include <cppuhelper/implbase2.hxx>
#include <svgio/svgreader/svgdocumenthandler.hxx>
#include <com/sun/star/xml/sax/XParser.hpp>
@@ -131,6 +132,14 @@
// get parser
uno::Reference< xml::sax::XParser > xParser(
xml::sax::Parser::create(context_));
+ // fdo#60471 need to enable internal entities because
+ // certain ... popular proprietary products write SVG files
+ // that use entities to define XML namespaces.
+ uno::Reference<lang::XInitialization> const xInit(xParser,
+ uno::UNO_QUERY_THROW);
+ uno::Sequence<uno::Any> args(1);
+ args[0] <<= OUString("DoSmeplease");
+ xInit->initialize(args);
// connect parser and filter
xParser->setDocumentHandler(xSvgDocHdl);
--
To view, visit https://gerrit.libreoffice.org/2138
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I147acac61dfe0b626268fe1e600dcf641ca63a0c
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Michael Stahl <mstahl at redhat.com>
More information about the LibreOffice
mailing list