Kaydet (Commit) 1a658831 authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz#4539 depth protect mathtype parser

Change-Id: I46e12f52d56e7802b676309207904b4d1894d236
Reviewed-on: https://gerrit.libreoffice.org/45928Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 495ac1bc
...@@ -41,6 +41,24 @@ class SmParser ...@@ -41,6 +41,24 @@ class SmParser
m_nColOff; // 0-based m_nColOff; // 0-based
bool m_bImportSymNames, bool m_bImportSymNames,
m_bExportSymNames; m_bExportSymNames;
sal_Int32 m_nParseDepth;
class DepthProtect
{
private:
sal_Int32& m_rParseDepth;
public:
DepthProtect(sal_Int32& rParseDepth)
: m_rParseDepth(rParseDepth)
{
++m_rParseDepth;
}
bool TooDeep() const { return m_rParseDepth > 2048; }
~DepthProtect()
{
--m_rParseDepth;
}
};
// map of used symbols (used to reduce file size by exporting only actually used symbols) // map of used symbols (used to reduce file size by exporting only actually used symbols)
std::set< OUString > m_aUsedSymbols; std::set< OUString > m_aUsedSymbols;
......
...@@ -297,11 +297,11 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent( ...@@ -297,11 +297,11 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(
if ( pFilter && pFilter->GetSuccess() ) if ( pFilter && pFilter->GetSuccess() )
nError = ERRCODE_NONE; nError = ERRCODE_NONE;
} }
catch( xml::sax::SAXParseException& r ) catch (const xml::sax::SAXParseException& r)
{ {
// sax parser sends wrapped exceptions, // sax parser sends wrapped exceptions,
// try to find the original one // try to find the original one
xml::sax::SAXException aSaxEx = *static_cast<xml::sax::SAXException*>(&r); xml::sax::SAXException aSaxEx = *static_cast<const xml::sax::SAXException*>(&r);
bool bTryChild = true; bool bTryChild = true;
while( bTryChild ) while( bTryChild )
...@@ -320,7 +320,7 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent( ...@@ -320,7 +320,7 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(
if ( bEncrypted ) if ( bEncrypted )
nError = ERRCODE_SFX_WRONGPASSWORD; nError = ERRCODE_SFX_WRONGPASSWORD;
} }
catch( const xml::sax::SAXException& r ) catch (const xml::sax::SAXException& r)
{ {
packages::zip::ZipIOException aBrokenPackage; packages::zip::ZipIOException aBrokenPackage;
if ( r.WrappedException >>= aBrokenPackage ) if ( r.WrappedException >>= aBrokenPackage )
...@@ -329,11 +329,14 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent( ...@@ -329,11 +329,14 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(
if ( bEncrypted ) if ( bEncrypted )
nError = ERRCODE_SFX_WRONGPASSWORD; nError = ERRCODE_SFX_WRONGPASSWORD;
} }
catch( packages::zip::ZipIOException& ) catch (const packages::zip::ZipIOException&)
{ {
nError = ERRCODE_IO_BROKENPACKAGE; nError = ERRCODE_IO_BROKENPACKAGE;
} }
catch( io::IOException& ) catch (const io::IOException&)
{
}
catch (const std::range_error&)
{ {
} }
...@@ -3131,7 +3134,9 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportMML(SvStream &rStream) ...@@ -3131,7 +3134,9 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportMML(SvStream &rStream)
//to update the properties, which throws cause the properties are uninitialized //to update the properties, which throws cause the properties are uninitialized
xDocSh->SetLoading(SfxLoadedFlags::NONE); xDocSh->SetLoading(SfxLoadedFlags::NONE);
auto nRet = SmXMLImportWrapper::ReadThroughComponent(xStream, xModel, xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter", false); ErrCode nRet = ERRCODE_SFX_DOLOADFAILED;
nRet = SmXMLImportWrapper::ReadThroughComponent(xStream, xModel, xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter", false);
xDocSh->SetLoading(SfxLoadedFlags::ALL); xDocSh->SetLoading(SfxLoadedFlags::ALL);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment