summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2024-05-17 16:44:12 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-05-21 08:33:10 +0200
commite39c57022afbe84601f58ef5bae0f12e69d33fc5 (patch)
tree679cb663209acdf64f5b45b699d0059cbf55994b /sw
parentae798781ef4df7a1fdef13af0bc459bf4f6e7b4c (diff)
writerfilter: avoid infinit loop when resolving embeddings on docx
If a docx file contains a loop on the .rels files for headers and/or footers the code would enter an infinite recursion while looking for embeddings. Change-Id: I2122fd6b1677812f561e96a9511a61b0e938e94a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167784 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/writerfilter/cppunittests/ooxml/data/recursive_header_rels.docxbin0 -> 16911 bytes
-rw-r--r--sw/qa/writerfilter/cppunittests/ooxml/ooxml.cxx7
-rw-r--r--sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx3
-rw-r--r--sw/source/writerfilter/ooxml/OOXMLDocumentImpl.hxx2
4 files changed, 11 insertions, 1 deletions
diff --git a/sw/qa/writerfilter/cppunittests/ooxml/data/recursive_header_rels.docx b/sw/qa/writerfilter/cppunittests/ooxml/data/recursive_header_rels.docx
new file mode 100644
index 000000000000..8000760017ed
--- /dev/null
+++ b/sw/qa/writerfilter/cppunittests/ooxml/data/recursive_header_rels.docx
Binary files differ
diff --git a/sw/qa/writerfilter/cppunittests/ooxml/ooxml.cxx b/sw/qa/writerfilter/cppunittests/ooxml/ooxml.cxx
index c146560ed352..5cbd9e219449 100644
--- a/sw/qa/writerfilter/cppunittests/ooxml/ooxml.cxx
+++ b/sw/qa/writerfilter/cppunittests/ooxml/ooxml.cxx
@@ -62,6 +62,13 @@ CPPUNIT_TEST_FIXTURE(Test, testFloatingTableLeak)
CPPUNIT_ASSERT(xParagraph->supportsService("com.sun.star.text.Paragraph"));
CPPUNIT_ASSERT(!xParaEnum->hasMoreElements());
}
+
+CPPUNIT_TEST_FIXTURE(Test, testRecursiveHeaderRels)
+{
+ // Given a document with self-referencing rels in a header/footer:
+ loadFromFile(u"recursive_header_rels.docx");
+ // It should not crash/hang on load
+}
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx
index 0530969fbccc..0fdf1b927956 100644
--- a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx
+++ b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.cxx
@@ -762,8 +762,9 @@ void OOXMLDocumentImpl::resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pS
{
importSubStreamRelations(pStream, OOXMLStream::CHARTS);
}
- if(bHeaderFooterFound)
+ if (bHeaderFooterFound && !maSeenStreams.contains(customTarget))
{
+ maSeenStreams.insert(customTarget);
try
{
OOXMLStream::Pointer_t Stream = OOXMLDocumentFactory::createStream(pStream, streamType);
diff --git a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.hxx b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.hxx
index 87aae13ab94f..ee8a01972f93 100644
--- a/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.hxx
+++ b/sw/source/writerfilter/ooxml/OOXMLDocumentImpl.hxx
@@ -30,6 +30,7 @@
#include <vector>
#include <stack>
+#include <set>
namespace writerfilter::ooxml
{
@@ -55,6 +56,7 @@ class OOXMLDocumentImpl : public OOXMLDocument
css::uno::Reference<css::io::XInputStream> mxEmbeddings;
css::uno::Sequence < css::beans::PropertyValue > mxEmbeddingsList;
std::vector<css::beans::PropertyValue> m_aEmbeddings;
+ std::set<OUString> maSeenStreams;
bool mbIsSubstream;
bool mbSkipImages;
/// How many paragraphs equal to 1 percent?