diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-01-21 17:51:14 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-01-22 00:45:57 +0100 |
commit | f1d1eb2c647af7b751b024faef09e01d849aacbb (patch) | |
tree | fcdb2e4e5929c5a514a11d75fc0ffbec6fb9a927 /starmath | |
parent | 6763c0ce90825b23a839fac2cd7aede5772c8993 (diff) |
ofz#5526 restrict mml parsing depth
Change-Id: Ib74787137112fb8402a2f6400ab4313d43c103dc
Reviewed-on: https://gerrit.libreoffice.org/48277
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/mathmlimport.cxx | 24 | ||||
-rw-r--r-- | starmath/source/mathmlimport.hxx | 5 |
2 files changed, 25 insertions, 4 deletions
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx index 032feb61a260..62a705cae930 100644 --- a/starmath/source/mathmlimport.cxx +++ b/starmath/source/mathmlimport.cxx @@ -410,7 +410,8 @@ SmXMLImport::SmXMLImport( const css::uno::Reference< css::uno::XComponentContext >& rContext, OUString const & implementationName, SvXMLImportFlags nImportFlags) : SvXMLImport(rContext, implementationName, nImportFlags), - bSuccess(false) + bSuccess(false), + nParseDepth(0) { } @@ -536,7 +537,15 @@ class SmXMLImportContext: public SvXMLImportContext public: SmXMLImportContext( SmXMLImport &rImport, sal_uInt16 nPrfx, const OUString& rLName) - : SvXMLImportContext(rImport, nPrfx, rLName) {} + : SvXMLImportContext(rImport, nPrfx, rLName) + { + GetSmImport().IncParseDepth(); + } + + virtual ~SmXMLImportContext() override + { + GetSmImport().DecParseDepth(); + } SmXMLImport& GetSmImport() { @@ -546,6 +555,12 @@ public: virtual void TCharacters(const OUString & /*rChars*/); virtual void Characters(const OUString &rChars) override; virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/) override; + virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>& rAttrList) override + { + if (GetSmImport().TooDeep()) + throw std::range_error("too deep"); + SvXMLImportContext::StartElement(rAttrList); + } }; void SmXMLImportContext::TCharacters(const OUString & /*rChars*/) @@ -906,7 +921,9 @@ public: SmXMLRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, const OUString& rLName) : SmXMLDocContext_Impl(rImport,nPrefix,rLName) - { nElementCount = GetSmImport().GetNodeStack().size(); } + , nElementCount(GetSmImport().GetNodeStack().size()) + { + } virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList) override; @@ -916,7 +933,6 @@ public: void EndElement() override; }; - class SmXMLEncloseContext_Impl : public SmXMLRowContext_Impl { public: diff --git a/starmath/source/mathmlimport.hxx b/starmath/source/mathmlimport.hxx index 3d017c1a25a7..a0d2c6254f0c 100644 --- a/starmath/source/mathmlimport.hxx +++ b/starmath/source/mathmlimport.hxx @@ -80,6 +80,7 @@ class SmXMLImport : public SvXMLImport SmNodeStack aNodeStack; bool bSuccess; + int nParseDepth; OUString aText; public: @@ -181,6 +182,10 @@ public: virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override; virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override; + + void IncParseDepth() { ++nParseDepth; } + bool TooDeep() const { return nParseDepth >= 2048; } + void DecParseDepth() { --nParseDepth; } }; |