/src/libreoffice/vcl/workben/rtf2pdffuzzer.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
10 | | #include <tools/stream.hxx> |
11 | | #include <vcl/FilterConfigItem.hxx> |
12 | | #include <com/sun/star/awt/XToolkit.hpp> |
13 | | #include <com/sun/star/ucb/XContentProvider.hpp> |
14 | | #include <com/sun/star/ucb/XUniversalContentBroker.hpp> |
15 | | #include <libxml/parser.h> |
16 | | #include "commonfuzzer.hxx" |
17 | | |
18 | | extern "C" bool TestPDFExportRTF(SvStream& rStream); |
19 | | |
20 | | extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) |
21 | 14 | { |
22 | 14 | if (__lsan_disable) |
23 | 0 | __lsan_disable(); |
24 | | |
25 | 14 | CommonInitialize(argc, argv); |
26 | | |
27 | | // initialise unconfigured UCB: |
28 | 14 | css::uno::Reference<css::ucb::XUniversalContentBroker> xUcb( |
29 | 14 | comphelper::getProcessServiceFactory()->createInstance( |
30 | 14 | "com.sun.star.ucb.UniversalContentBroker"), |
31 | 14 | css::uno::UNO_QUERY_THROW); |
32 | 14 | css::uno::Sequence<css::uno::Any> aArgs{ css::uno::Any(OUString("NoConfig")) }; |
33 | 14 | css::uno::Reference<css::ucb::XContentProvider> xFileProvider( |
34 | 14 | comphelper::getProcessServiceFactory()->createInstanceWithArguments( |
35 | 14 | "com.sun.star.ucb.FileContentProvider", aArgs), |
36 | 14 | css::uno::UNO_QUERY_THROW); |
37 | 14 | xUcb->registerContentProvider(xFileProvider, "file", true); |
38 | | |
39 | | // create and hold a reference to XToolkit here to avoid the lsan warning about its leak |
40 | | // due to getting created in the unusual case of no vcl main loop |
41 | 14 | static css::uno::Reference<css::awt::XToolkit> xTk( |
42 | 14 | comphelper::getProcessServiceFactory()->createInstance("com.sun.star.awt.Toolkit"), |
43 | 14 | css::uno::UNO_QUERY_THROW); |
44 | | |
45 | 14 | if (__lsan_enable) |
46 | 0 | __lsan_enable(); |
47 | | |
48 | 14 | return 0; |
49 | 14 | } |
50 | | |
51 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
52 | 30.3k | { |
53 | 30.3k | SvMemoryStream aStream(const_cast<uint8_t*>(data), size, StreamMode::READ); |
54 | 30.3k | bool bRTFLoaded = TestPDFExportRTF(aStream); |
55 | | // if the rtf didn't load then reject so that input will not be added to the corpus |
56 | | // we're not interested in input that doesn't go on to exercise the pdf export |
57 | 30.3k | return bRTFLoaded ? 0 : -1; |
58 | 30.3k | } |
59 | | |
60 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |