summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-09-22 12:32:28 +0100
committerCaolán McNamara <caolanm@redhat.com>2017-09-22 18:09:44 +0200
commit893c08b59abf31ee0ae50c4ac030b006c43c0976 (patch)
tree750ab03b55ec72c55dbc1640d5d5d4222e04e88b
parenta395698d3df12d1deaec25b31ae02e019a281867 (diff)
move TestImportOLE2 where it can be used by fftester
Change-Id: I7b41d9ec673cfb96f51b5008540df63fe78a7581 Reviewed-on: https://gerrit.libreoffice.org/42639 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sot/source/sdstor/stg.cxx1
-rw-r--r--sot/source/sdstor/storage.cxx48
-rw-r--r--vcl/workben/fftester.cxx15
-rw-r--r--vcl/workben/olefuzzer.cxx54
4 files changed, 64 insertions, 54 deletions
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx
index 67ea06b8f815..f82cd30d5e80 100644
--- a/sot/source/sdstor/stg.cxx
+++ b/sot/source/sdstor/stg.cxx
@@ -941,5 +941,4 @@ bool Storage::Equals( const BaseStorage& rStorage ) const
return pOther && ( pOther->pEntry == pEntry );
}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx
index 4445872b5f2b..9d19bafafedb 100644
--- a/sot/source/sdstor/storage.cxx
+++ b/sot/source/sdstor/storage.cxx
@@ -809,4 +809,52 @@ sal_Int32 SotStorage::GetVersion( const css::uno::Reference < css::embed::XStora
return 0;
}
+namespace
+{
+ void traverse(const tools::SvRef<SotStorage>& rStorage, std::vector<unsigned char>& rBuf)
+ {
+ SvStorageInfoList infos;
+
+ rStorage->FillInfoList(&infos);
+
+ for (const auto& info: infos)
+ {
+ if (info.IsStream())
+ {
+ // try to open and read all content
+ tools::SvRef<SotStorageStream> xStream(rStorage->OpenSotStream(info.GetName(), StreamMode::STD_READ));
+ const size_t nSize = xStream->GetSize();
+ const size_t nRead = xStream->ReadBytes(rBuf.data(), nSize);
+ SAL_INFO("sot", "Read " << nRead << "bytes");
+ }
+ else if (info.IsStorage())
+ {
+ tools::SvRef<SotStorage> xStorage(rStorage->OpenSotStorage(info.GetName(), StreamMode::STD_READ));
+
+ // continue with children
+ traverse(xStorage, rBuf);
+ }
+ else
+ {
+ }
+ }
+ }
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportOLE2(SvStream &rStream)
+{
+ try
+ {
+ size_t nSize = rStream.remainingSize();
+ tools::SvRef<SotStorage> xRootStorage(new SotStorage(&rStream, false));
+ std::vector<unsigned char> aTmpBuf(nSize);
+ traverse(xRootStorage, aTmpBuf);
+ }
+ catch (...)
+ {
+ return false;
+ }
+ return true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx
index 4b9d6979ae54..4e806216d956 100644
--- a/vcl/workben/fftester.cxx
+++ b/vcl/workben/fftester.cxx
@@ -532,7 +532,20 @@ try_again:
SvFileStream aFileStream(out, StreamMode::READ);
ret = (int) (*pfnImport)(aFileStream);
}
-
+ else if (strcmp(argv[2], "ole") == 0)
+ {
+ static FFilterCall pfnImport(nullptr);
+ if (!pfnImport)
+ {
+ osl::Module aLibrary;
+ aLibrary.loadRelative(&thisModule, "libsotlo.so", SAL_LOADMODULE_LAZY);
+ pfnImport = reinterpret_cast<FFilterCall>(
+ aLibrary.getFunctionSymbol("TestImportOLE2"));
+ aLibrary.release();
+ }
+ SvFileStream aFileStream(out, StreamMode::READ);
+ ret = (int) (*pfnImport)(aFileStream);
+ }
#endif
}
diff --git a/vcl/workben/olefuzzer.cxx b/vcl/workben/olefuzzer.cxx
index f9a717122e59..6554b723f955 100644
--- a/vcl/workben/olefuzzer.cxx
+++ b/vcl/workben/olefuzzer.cxx
@@ -7,60 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <vector>
-
-#include <sot/storage.hxx>
-
#include <tools/stream.hxx>
-
#include "commonfuzzer.hxx"
-namespace
-{
-
-void traverse(const tools::SvRef<SotStorage>& rStorage, std::vector<unsigned char>& rBuf)
-{
- SvStorageInfoList infos;
-
- rStorage->FillInfoList(&infos);
-
- for (const auto& info: infos)
- {
- if (info.IsStream())
- {
- // try to open and read all content
- tools::SvRef<SotStorageStream> xStream(rStorage->OpenSotStream(info.GetName(), StreamMode::STD_READ));
- const size_t nSize = xStream->GetSize();
- const size_t nRead = xStream->ReadBytes(rBuf.data(), nSize);
- (void) nRead;
- }
- else if (info.IsStorage())
- {
- tools::SvRef<SotStorage> xStorage(rStorage->OpenSotStorage(info.GetName(), StreamMode::STD_READ));
-
- // continue with children
- traverse(xStorage, rBuf);
- }
- else
- {
- }
- }
-}
-
-void TestImportOLE2(SvStream &rStream, size_t nSize)
-{
- try
- {
- tools::SvRef<SotStorage> xRootStorage(new SotStorage(&rStream, false));
- std::vector<unsigned char> aTmpBuf(nSize);
- traverse(xRootStorage, aTmpBuf);
- }
- catch (...)
- {
- }
-}
-
-}
+extern "C" bool TestImportOLE2(SvStream &rStream);
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
@@ -71,7 +21,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ);
- TestImportOLE2(aStream, size);
+ TestImportOLE2(aStream);
return 0;
}