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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 export CC=afl-clang-fast
22 export CXX=afl-clang-fast++
24 cp workdir/LinkTarget/Executable/fftester instdir/program
25 LD_LIBRARY_PATH=`pwd`/instdir/program SAL_USE_VCLPLUGIN=svp AFL_PERSISTENT=1 afl-fuzz -t 50 -i ~/fuzz/in.png -o ~/fuzz/out.png -d -T png -m 50000000 instdir/program/fftester @@ png
27 On slower file formats like .doc you can probably drop the -t and rely on the
28 estimations, on faster file formats ironically not specifing a timeout will
29 result in a hilarious dramatic falloff in performance from thousands per second
30 to teens per second as tiny variations from the initial calculated
31 timeout will trigger a shutdown of the fftester and a restart and the
32 startup time is woeful (hence the AFL_PERSISTENT mode in the first place)
36 #include <tools/extendapplicationenvironment.hxx>
38 #include <cppuhelper/bootstrap.hxx>
39 #include <comphelper/processfactory.hxx>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <unotools/configmgr.hxx>
44 #include <vcl/dibtools.hxx>
45 #include <vcl/event.hxx>
46 #include <vcl/graphicfilter.hxx>
47 #include <vcl/pngread.hxx>
48 #include <vcl/svapp.hxx>
49 #include <vcl/wmf.hxx>
50 #include <vcl/wrkwin.hxx>
51 #include <vcl/fltcall.hxx>
52 #include <osl/file.hxx>
55 #include <../source/filter/igif/gifread.hxx>
56 #include <../source/filter/ixbm/xbmread.hxx>
57 #include <../source/filter/ixpm/xpmread.hxx>
58 #include <../source/filter/jpeg/jpeg.hxx>
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::lang
;
64 extern "C" { static void SAL_CALL
thisModule() {} }
66 typedef bool (*WFilterCall
)(const OUString
&rUrl
, const OUString
&rFlt
);
67 typedef bool (*HFilterCall
)(const OUString
&rUrl
);
69 /* This constant specifies the number of inputs to process before restarting.
70 * This is optional, but helps limit the impact of memory leaks and similar
73 #define PERSIST_MAX 1000
74 unsigned int persist_cnt
;
76 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
83 fprintf(stderr
, "Usage: fftester <filename> <wmf|jpg>\n");
87 OUString
in(argv
[1], strlen(argv
[1]), RTL_TEXTENCODING_UTF8
);
89 osl::File::getFileURLFromSystemPath(in
, out
);
91 tools::extendApplicationEnvironment();
93 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
94 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
95 if( !xServiceManager
.is() )
96 Application::Abort( "Failed to bootstrap" );
97 comphelper::setProcessServiceFactory( xServiceManager
);
98 utl::ConfigManager::EnableAvoidConfig();
104 if (strcmp(argv
[2], "wmf") == 0 || strcmp(argv
[2], "emf") == 0)
106 GDIMetaFile aGDIMetaFile
;
107 SvFileStream
aFileStream(out
, StreamMode::READ
);
108 ret
= (int) ReadWindowMetafile(aFileStream
, aGDIMetaFile
);
110 else if (strcmp(argv
[2], "jpg") == 0)
113 SvFileStream
aFileStream(out
, StreamMode::READ
);
114 ret
= (int) ImportJPEG(aFileStream
, aGraphic
, nullptr, GraphicFilterImportFlags::NONE
);
116 else if (strcmp(argv
[2], "gif") == 0)
118 SvFileStream
aFileStream(out
, StreamMode::READ
);
120 ret
= (int) ImportGIF(aFileStream
, aGraphic
);
122 else if (strcmp(argv
[2], "xbm") == 0)
125 SvFileStream
aFileStream(out
, StreamMode::READ
);
126 ret
= (int) ImportXBM(aFileStream
, aGraphic
);
128 else if (strcmp(argv
[2], "xpm") == 0)
131 SvFileStream
aFileStream(out
, StreamMode::READ
);
132 ret
= (int) ImportXPM(aFileStream
, aGraphic
);
134 else if (strcmp(argv
[2], "png") == 0)
136 SvFileStream
aFileStream(out
, StreamMode::READ
);
137 vcl::PNGReader
aReader(aFileStream
);
140 else if (strcmp(argv
[2], "bmp") == 0)
143 SvFileStream
aFileStream(out
, StreamMode::READ
);
144 ret
= (int) ReadDIB(aTarget
, aFileStream
, true);
146 else if (strcmp(argv
[2], "svm") == 0)
148 GDIMetaFile aGDIMetaFile
;
149 SvFileStream
aFileStream(out
, StreamMode::READ
);
150 ReadGDIMetaFile(aFileStream
, aGDIMetaFile
);
152 else if (strcmp(argv
[2], "pcd") == 0)
154 static PFilterCall
pfnImport(nullptr);
157 osl::Module aLibrary
;
158 aLibrary
.loadRelative(&thisModule
, "libicdlo.so");
159 pfnImport
= reinterpret_cast<PFilterCall
>(
160 aLibrary
.getFunctionSymbol("GraphicImport"));
164 SvFileStream
aFileStream(out
, StreamMode::READ
);
165 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
167 else if (strcmp(argv
[2], "dxf") == 0)
169 static PFilterCall
pfnImport(nullptr);
172 osl::Module aLibrary
;
173 aLibrary
.loadRelative(&thisModule
, "libidxlo.so");
174 pfnImport
= reinterpret_cast<PFilterCall
>(
175 aLibrary
.getFunctionSymbol("GraphicImport"));
179 SvFileStream
aFileStream(out
, StreamMode::READ
);
180 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
182 else if (strcmp(argv
[2], "met") == 0)
184 static PFilterCall
pfnImport(nullptr);
187 osl::Module aLibrary
;
188 aLibrary
.loadRelative(&thisModule
, "libimelo.so");
189 pfnImport
= reinterpret_cast<PFilterCall
>(
190 aLibrary
.getFunctionSymbol("GraphicImport"));
194 SvFileStream
aFileStream(out
, StreamMode::READ
);
195 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
197 else if ((strcmp(argv
[2], "pbm") == 0) || strcmp(argv
[2], "ppm") == 0)
199 static PFilterCall
pfnImport(nullptr);
202 osl::Module aLibrary
;
203 aLibrary
.loadRelative(&thisModule
, "libipblo.so");
204 pfnImport
= reinterpret_cast<PFilterCall
>(
205 aLibrary
.getFunctionSymbol("GraphicImport"));
209 SvFileStream
aFileStream(out
, StreamMode::READ
);
210 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
212 else if (strcmp(argv
[2], "psd") == 0)
214 static PFilterCall
pfnImport(nullptr);
217 osl::Module aLibrary
;
218 aLibrary
.loadRelative(&thisModule
, "libipdlo.so");
219 pfnImport
= reinterpret_cast<PFilterCall
>(
220 aLibrary
.getFunctionSymbol("GraphicImport"));
224 SvFileStream
aFileStream(out
, StreamMode::READ
);
225 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
227 else if (strcmp(argv
[2], "eps") == 0)
229 static PFilterCall
pfnImport(nullptr);
232 osl::Module aLibrary
;
233 aLibrary
.loadRelative(&thisModule
, "libipslo.so");
234 pfnImport
= reinterpret_cast<PFilterCall
>(
235 aLibrary
.getFunctionSymbol("GraphicImport"));
239 SvFileStream
aFileStream(out
, StreamMode::READ
);
240 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
242 else if (strcmp(argv
[2], "pct") == 0)
244 static PFilterCall
pfnImport(nullptr);
247 osl::Module aLibrary
;
248 aLibrary
.loadRelative(&thisModule
, "libiptlo.so");
249 pfnImport
= reinterpret_cast<PFilterCall
>(
250 aLibrary
.getFunctionSymbol("GraphicImport"));
254 SvFileStream
aFileStream(out
, StreamMode::READ
);
255 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
257 else if (strcmp(argv
[2], "pcx") == 0)
259 static PFilterCall
pfnImport(nullptr);
262 osl::Module aLibrary
;
263 aLibrary
.loadRelative(&thisModule
, "libipxlo.so");
264 pfnImport
= reinterpret_cast<PFilterCall
>(
265 aLibrary
.getFunctionSymbol("GraphicImport"));
269 SvFileStream
aFileStream(out
, StreamMode::READ
);
270 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
272 else if (strcmp(argv
[2], "ras") == 0)
274 static PFilterCall
pfnImport(nullptr);
277 osl::Module aLibrary
;
278 aLibrary
.loadRelative(&thisModule
, "libiralo.so");
279 pfnImport
= reinterpret_cast<PFilterCall
>(
280 aLibrary
.getFunctionSymbol("GraphicImport"));
284 SvFileStream
aFileStream(out
, StreamMode::READ
);
285 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
287 else if (strcmp(argv
[2], "tga") == 0)
289 static PFilterCall
pfnImport(nullptr);
292 osl::Module aLibrary
;
293 aLibrary
.loadRelative(&thisModule
, "libitglo.so");
294 pfnImport
= reinterpret_cast<PFilterCall
>(
295 aLibrary
.getFunctionSymbol("GraphicImport"));
299 SvFileStream
aFileStream(out
, StreamMode::READ
);
300 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
302 else if (strcmp(argv
[2], "tif") == 0)
304 static PFilterCall
pfnImport(nullptr);
307 osl::Module aLibrary
;
308 aLibrary
.loadRelative(&thisModule
, "libitilo.so");
309 pfnImport
= reinterpret_cast<PFilterCall
>(
310 aLibrary
.getFunctionSymbol("GraphicImport"));
314 SvFileStream
aFileStream(out
, StreamMode::READ
);
315 ret
= (int) (*pfnImport
)(aFileStream
, aTarget
, nullptr);
317 else if ( (strcmp(argv
[2], "doc") == 0) ||
318 (strcmp(argv
[2], "ww8") == 0) ||
319 (strcmp(argv
[2], "ww6") == 0) ||
320 (strcmp(argv
[2], "ww2") == 0) )
322 static WFilterCall
pfnImport(nullptr);
325 osl::Module aLibrary
;
326 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
327 pfnImport
= reinterpret_cast<WFilterCall
>(
328 aLibrary
.getFunctionSymbol("TestImportDOC"));
331 if (strcmp(argv
[2], "ww6") == 0)
332 ret
= (int) (*pfnImport
)(out
, OUString("CWW6"));
333 else if (strcmp(argv
[2], "ww2") == 0)
334 ret
= (int) (*pfnImport
)(out
, OUString("WW6"));
336 ret
= (int) (*pfnImport
)(out
, OUString("CWW8"));
338 else if ( (strcmp(argv
[2], "xls") == 0) ||
339 (strcmp(argv
[2], "wb2") == 0) )
341 static WFilterCall
pfnImport(nullptr);
344 osl::Module aLibrary
;
345 aLibrary
.loadRelative(&thisModule
, "libscfiltlo.so", SAL_LOADMODULE_LAZY
);
346 pfnImport
= reinterpret_cast<WFilterCall
>(
347 aLibrary
.getFunctionSymbol("TestImportSpreadsheet"));
350 ret
= (int) (*pfnImport
)(out
, OUString(argv
[2], strlen(argv
[2]), RTL_TEXTENCODING_UTF8
));
352 else if (strcmp(argv
[2], "hwp") == 0)
354 static HFilterCall
pfnImport(nullptr);
357 osl::Module aLibrary
;
358 aLibrary
.loadRelative(&thisModule
, "libhwplo.so", SAL_LOADMODULE_LAZY
);
359 pfnImport
= reinterpret_cast<HFilterCall
>(
360 aLibrary
.getFunctionSymbol("TestImportHWP"));
363 ret
= (int) (*pfnImport
)(out
);
365 else if (strcmp(argv
[2], "602") == 0)
367 static HFilterCall
pfnImport(nullptr);
370 osl::Module aLibrary
;
371 aLibrary
.loadRelative(&thisModule
, "libt602filterlo.so", SAL_LOADMODULE_LAZY
);
372 pfnImport
= reinterpret_cast<HFilterCall
>(
373 aLibrary
.getFunctionSymbol("TestImport602"));
376 ret
= (int) (*pfnImport
)(out
);
378 else if (strcmp(argv
[2], "lwp") == 0)
380 static HFilterCall
pfnImport(nullptr);
383 osl::Module aLibrary
;
384 aLibrary
.loadRelative(&thisModule
, "liblwpftlo.so", SAL_LOADMODULE_LAZY
);
385 pfnImport
= reinterpret_cast<HFilterCall
>(
386 aLibrary
.getFunctionSymbol("TestImportLWP"));
389 ret
= (int) (*pfnImport
)(out
);
391 else if (strcmp(argv
[2], "ppt") == 0)
393 static HFilterCall
pfnImport(nullptr);
396 osl::Module aLibrary
;
397 aLibrary
.loadRelative(&thisModule
, "libsdfiltlo.so", SAL_LOADMODULE_LAZY
);
398 pfnImport
= reinterpret_cast<HFilterCall
>(
399 aLibrary
.getFunctionSymbol("TestImportPPT"));
402 ret
= (int) (*pfnImport
)(out
);
406 /* To signal successful completion of a run, we need to deliver
407 SIGSTOP to our own process, then loop to the very beginning
408 once we're resumed by the supervisor process. We do this only
409 if AFL_PERSISTENT is set to retain normal behavior when the
410 program is executed directly; and take note of PERSIST_MAX. */
411 if (getenv("AFL_PERSISTENT") && persist_cnt
++ < PERSIST_MAX
)
417 /* If AFL_PERSISTENT not set or PERSIST_MAX exceeded, exit normally. */
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */