summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-09-19 10:40:03 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-09-21 09:55:44 +0200
commit4e302884ce0c05bbfd9b069cb969355d2f30c17d (patch)
tree4222f3f2ad0e63aec47e07a236ca4941a459a4ee /sc
parent81c7311609d5c9b5ebf7348e805276a8864dadcf (diff)
add fods fuzzer
Change-Id: I3cc5a0d8bb24dd33b63ed82866a4acfb7a2dd043 Reviewed-on: https://gerrit.libreoffice.org/42459 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/xml/xmlimprt.cxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 7bc07d66abb4..5ffc31cbf86a 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -29,6 +29,7 @@
#include <xmloff/xmlictxt.hxx>
#include <xmloff/xmlmetai.hxx>
#include <sfx2/objsh.hxx>
+#include <unotools/streamwrap.hxx>
#include <xmloff/xmlnumfi.hxx>
#include <xmloff/xmlscripti.hxx>
#include <xmloff/XMLFontStylesContext.hxx>
@@ -77,6 +78,7 @@
#include <numformat.hxx>
#include <comphelper/extract.hxx>
+#include <comphelper/propertysequence.hxx>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/frame/XModel.hpp>
@@ -2051,4 +2053,51 @@ ScMyImpDetectiveOpArray* ScXMLImport::GetDetectiveOpArray()
return pDetectiveOpArray;
}
+extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportFODS(SvStream &rStream)
+{
+ ScDLL::Init();
+
+ SfxObjectShellLock xDocSh(new ScDocShell);
+ xDocSh->DoInitNew();
+ uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
+
+ uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
+ uno::Reference<io::XInputStream> xStream(new ::utl::OSeekableInputStreamWrapper(rStream));
+ uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance("com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_QUERY_THROW);
+
+ css::uno::Sequence<OUString> aUserData(7);
+ aUserData[0] = "com.sun.star.comp.filter.OdfFlatXml";
+ aUserData[2] = "com.sun.star.comp.Calc.XMLOasisImporter";
+ aUserData[3] = "com.sun.star.comp.Calc.XMLOasisExporter";
+ aUserData[6] = "true";
+ uno::Sequence<beans::PropertyValue> aAdaptorArgs(comphelper::InitPropertySequence(
+ {
+ { "UserData", uno::Any(aUserData) },
+ }));
+ css::uno::Sequence<uno::Any> aOuterArgs(1);
+ aOuterArgs[0] <<= aAdaptorArgs;
+
+ uno::Reference<lang::XInitialization> xInit(xInterface, uno::UNO_QUERY_THROW);
+ xInit->initialize(aOuterArgs);
+
+ uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW);
+ uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
+ {
+ { "InputStream", uno::Any(xStream) },
+ { "URL", uno::Any(OUString("private:stream")) },
+ }));
+ xImporter->setTargetDocument(xModel);
+
+ uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW);
+ //SetLoading hack because the document properties will be re-initted
+ //by the xml filter and during the init, while its considered uninitialized,
+ //setting a property will inform the document its modified, which attempts
+ //to update the properties, which throws cause the properties are uninitialized
+ xDocSh->SetLoading(SfxLoadedFlags::NONE);
+ bool ret = xFilter->filter(aArgs);
+ xDocSh->SetLoading(SfxLoadedFlags::ALL);
+
+ return ret;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */