Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / workben / olefuzzer.cxx
blobf9a717122e59bd981b86f731fde2d16e1b38df54
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <vector>
12 #include <sot/storage.hxx>
14 #include <tools/stream.hxx>
16 #include "commonfuzzer.hxx"
18 namespace
21 void traverse(const tools::SvRef<SotStorage>& rStorage, std::vector<unsigned char>& rBuf)
23 SvStorageInfoList infos;
25 rStorage->FillInfoList(&infos);
27 for (const auto& info: infos)
29 if (info.IsStream())
31 // try to open and read all content
32 tools::SvRef<SotStorageStream> xStream(rStorage->OpenSotStream(info.GetName(), StreamMode::STD_READ));
33 const size_t nSize = xStream->GetSize();
34 const size_t nRead = xStream->ReadBytes(rBuf.data(), nSize);
35 (void) nRead;
37 else if (info.IsStorage())
39 tools::SvRef<SotStorage> xStorage(rStorage->OpenSotStorage(info.GetName(), StreamMode::STD_READ));
41 // continue with children
42 traverse(xStorage, rBuf);
44 else
50 void TestImportOLE2(SvStream &rStream, size_t nSize)
52 try
54 tools::SvRef<SotStorage> xRootStorage(new SotStorage(&rStream, false));
55 std::vector<unsigned char> aTmpBuf(nSize);
56 traverse(xRootStorage, aTmpBuf);
58 catch (...)
65 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
67 TypicalFuzzerInitialize(argc, argv);
68 return 0;
71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
73 SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ);
74 TestImportOLE2(aStream, size);
75 return 0;
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */