1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <sot/storage.hxx>
14 #include <tools/stream.hxx>
16 #include "commonfuzzer.hxx"
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
)
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
);
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
);
50 void TestImportOLE2(SvStream
&rStream
, size_t nSize
)
54 tools::SvRef
<SotStorage
> xRootStorage(new SotStorage(&rStream
, false));
55 std::vector
<unsigned char> aTmpBuf(nSize
);
56 traverse(xRootStorage
, aTmpBuf
);
65 extern "C" int LLVMFuzzerInitialize(int *argc
, char ***argv
)
67 TypicalFuzzerInitialize(argc
, argv
);
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
);
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */