diff options
author | David Tardon <dtardon@redhat.com> | 2017-03-14 10:17:41 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-03-14 21:00:25 +0000 |
commit | 3fa34da687ba4be98319888a90cba6414b9f3fbe (patch) | |
tree | a03d24d1390da60c2c355fc444a7934b1f925366 /vcl/workben | |
parent | e68faf7d42179c4f9b90b514f5b3bfcb7f1e9cb0 (diff) |
add a separate fuzzer for OLE2
Change-Id: I518bd8dc6fd50e96746d6d415190551c6cbfdea5
Reviewed-on: https://gerrit.libreoffice.org/35178
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/workben')
-rw-r--r-- | vcl/workben/olefuzzer.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vcl/workben/olefuzzer.cxx b/vcl/workben/olefuzzer.cxx new file mode 100644 index 000000000000..349e27ecd28b --- /dev/null +++ b/vcl/workben/olefuzzer.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * 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) +{ + tools::SvRef<SotStorage> xRootStorage(new SotStorage(&rStream, false)); + std::vector<unsigned char> aTmpBuf(nSize); + traverse(xRootStorage, aTmpBuf); +} + +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ); + TestImportOLE2(aStream, size); + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |