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 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 specifying 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>
56 #include <../source/filter/igif/gifread.hxx>
57 #include <../source/filter/ixbm/xbmread.hxx>
58 #include <../source/filter/ixpm/xpmread.hxx>
59 #include <../source/filter/jpeg/jpeg.hxx>
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::lang
;
65 #ifndef DISABLE_DYNLOADING
66 extern "C" { static void SAL_CALL
thisModule() {} }
69 typedef bool (*WFilterCall
)(const OUString
&rUrl
, const OUString
&rFlt
);
70 typedef bool (*FFilterCall
)(SvStream
&rStream
);
72 /* This constant specifies the number of inputs to process before restarting.
73 * This is optional, but helps limit the impact of memory leaks and similar
76 #define PERSIST_MAX 1000
77 static unsigned int persist_cnt
;
79 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
86 fprintf(stderr
, "Usage: fftester <filename> <wmf|jpg>\n");
90 setenv("SAL_USE_VCLPLUGIN", "svp", 1);
91 setenv("JPEGMEM", "768M", 1);
92 setenv("SAL_WMF_COMPLEXCLIP_VIA_REGION", "1", 1);
93 setenv("SAL_DISABLE_PRINTERLIST", "1", 1);
94 setenv("SAL_NO_FONT_LOOKUP", "1", 1);
96 OUString
in(argv
[1], strlen(argv
[1]), RTL_TEXTENCODING_UTF8
);
98 osl::File::getFileURLFromSystemPath(in
, out
);
100 tools::extendApplicationEnvironment();
102 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
103 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
104 if( !xServiceManager
.is() )
105 Application::Abort( "Failed to bootstrap" );
106 comphelper::setProcessServiceFactory( xServiceManager
);
107 utl::ConfigManager::EnableAvoidConfig();
113 if (strcmp(argv
[2], "wmf") == 0 || strcmp(argv
[2], "emf") == 0)
115 GDIMetaFile aGDIMetaFile
;
116 SvFileStream
aFileStream(out
, StreamMode::READ
);
117 ret
= (int) ReadWindowMetafile(aFileStream
, aGDIMetaFile
);
119 else if (strcmp(argv
[2], "jpg") == 0)
122 SvFileStream
aFileStream(out
, StreamMode::READ
);
123 ret
= (int) ImportJPEG(aFileStream
, aGraphic
, GraphicFilterImportFlags::NONE
, nullptr);
125 else if (strcmp(argv
[2], "gif") == 0)
127 SvFileStream
aFileStream(out
, StreamMode::READ
);
129 ret
= (int) ImportGIF(aFileStream
, aGraphic
);
131 else if (strcmp(argv
[2], "xbm") == 0)
134 SvFileStream
aFileStream(out
, StreamMode::READ
);
135 ret
= (int) ImportXBM(aFileStream
, aGraphic
);
137 else if (strcmp(argv
[2], "xpm") == 0)
140 SvFileStream
aFileStream(out
, StreamMode::READ
);
141 ret
= (int) ImportXPM(aFileStream
, aGraphic
);
143 else if (strcmp(argv
[2], "png") == 0)
145 SvFileStream
aFileStream(out
, StreamMode::READ
);
146 vcl::PNGReader
aReader(aFileStream
);
148 else if (strcmp(argv
[2], "bmp") == 0)
151 SvFileStream
aFileStream(out
, StreamMode::READ
);
152 ret
= (int) ReadDIB(aTarget
, aFileStream
, true);
154 else if (strcmp(argv
[2], "svm") == 0)
156 GDIMetaFile aGDIMetaFile
;
157 SvFileStream
aFileStream(out
, StreamMode::READ
);
158 ReadGDIMetaFile(aFileStream
, aGDIMetaFile
);
160 #ifndef DISABLE_DYNLOADING
161 else if (strcmp(argv
[2], "pcd") == 0)
163 static PFilterCall
pfnImport(nullptr);
166 osl::Module aLibrary
;
167 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
168 pfnImport
= reinterpret_cast<PFilterCall
>(
169 aLibrary
.getFunctionSymbol("icdGraphicImport"));
173 SvFileStream
aFileStream(out
, StreamMode::READ
);
174 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
176 else if (strcmp(argv
[2], "dxf") == 0)
178 static PFilterCall
pfnImport(nullptr);
181 osl::Module aLibrary
;
182 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
183 pfnImport
= reinterpret_cast<PFilterCall
>(
184 aLibrary
.getFunctionSymbol("idxGraphicImport"));
188 SvFileStream
aFileStream(out
, StreamMode::READ
);
189 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
191 else if (strcmp(argv
[2], "met") == 0)
193 static PFilterCall
pfnImport(nullptr);
196 osl::Module aLibrary
;
197 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
198 pfnImport
= reinterpret_cast<PFilterCall
>(
199 aLibrary
.getFunctionSymbol("imeGraphicImport"));
203 SvFileStream
aFileStream(out
, StreamMode::READ
);
204 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
206 else if ((strcmp(argv
[2], "pbm") == 0) || strcmp(argv
[2], "ppm") == 0)
208 static PFilterCall
pfnImport(nullptr);
211 osl::Module aLibrary
;
212 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
213 pfnImport
= reinterpret_cast<PFilterCall
>(
214 aLibrary
.getFunctionSymbol("ipbGraphicImport"));
218 SvFileStream
aFileStream(out
, StreamMode::READ
);
219 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
221 else if (strcmp(argv
[2], "psd") == 0)
223 static PFilterCall
pfnImport(nullptr);
226 osl::Module aLibrary
;
227 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
228 pfnImport
= reinterpret_cast<PFilterCall
>(
229 aLibrary
.getFunctionSymbol("ipdGraphicImport"));
233 SvFileStream
aFileStream(out
, StreamMode::READ
);
234 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
236 else if (strcmp(argv
[2], "eps") == 0)
238 static PFilterCall
pfnImport(nullptr);
241 osl::Module aLibrary
;
242 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
243 pfnImport
= reinterpret_cast<PFilterCall
>(
244 aLibrary
.getFunctionSymbol("ipsGraphicImport"));
248 SvFileStream
aFileStream(out
, StreamMode::READ
);
249 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
251 else if (strcmp(argv
[2], "pct") == 0)
253 static PFilterCall
pfnImport(nullptr);
256 osl::Module aLibrary
;
257 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
258 pfnImport
= reinterpret_cast<PFilterCall
>(
259 aLibrary
.getFunctionSymbol("iptGraphicImport"));
263 SvFileStream
aFileStream(out
, StreamMode::READ
);
264 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
266 else if (strcmp(argv
[2], "pcx") == 0)
268 static PFilterCall
pfnImport(nullptr);
271 osl::Module aLibrary
;
272 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
273 pfnImport
= reinterpret_cast<PFilterCall
>(
274 aLibrary
.getFunctionSymbol("ipxGraphicImport"));
278 SvFileStream
aFileStream(out
, StreamMode::READ
);
279 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
281 else if (strcmp(argv
[2], "ras") == 0)
283 static PFilterCall
pfnImport(nullptr);
286 osl::Module aLibrary
;
287 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
288 pfnImport
= reinterpret_cast<PFilterCall
>(
289 aLibrary
.getFunctionSymbol("iraGraphicImport"));
293 SvFileStream
aFileStream(out
, StreamMode::READ
);
294 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
296 else if (strcmp(argv
[2], "tga") == 0)
298 static PFilterCall
pfnImport(nullptr);
301 osl::Module aLibrary
;
302 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
303 pfnImport
= reinterpret_cast<PFilterCall
>(
304 aLibrary
.getFunctionSymbol("itgGraphicImport"));
308 SvFileStream
aFileStream(out
, StreamMode::READ
);
309 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
311 else if (strcmp(argv
[2], "tif") == 0)
313 static PFilterCall
pfnImport(nullptr);
316 osl::Module aLibrary
;
317 aLibrary
.loadRelative(&thisModule
, "libgielo.so");
318 pfnImport
= reinterpret_cast<PFilterCall
>(
319 aLibrary
.getFunctionSymbol("itiGraphicImport"));
323 SvFileStream
aFileStream(out
, StreamMode::READ
);
324 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
326 else if ((strcmp(argv
[2], "doc") == 0) || (strcmp(argv
[2], "ww8") == 0))
328 static FFilterCall
pfnImport(nullptr);
331 osl::Module aLibrary
;
332 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
333 pfnImport
= reinterpret_cast<FFilterCall
>(
334 aLibrary
.getFunctionSymbol("TestImportWW8"));
337 SvFileStream
aFileStream(out
, StreamMode::READ
);
338 ret
= (int) (*pfnImport
)(aFileStream
);
340 else if (strcmp(argv
[2], "ww6") == 0)
342 static FFilterCall
pfnImport(nullptr);
345 osl::Module aLibrary
;
346 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
347 pfnImport
= reinterpret_cast<FFilterCall
>(
348 aLibrary
.getFunctionSymbol("TestImportWW6"));
351 SvFileStream
aFileStream(out
, StreamMode::READ
);
352 ret
= (int) (*pfnImport
)(aFileStream
);
354 else if (strcmp(argv
[2], "ww2") == 0)
356 static FFilterCall
pfnImport(nullptr);
359 osl::Module aLibrary
;
360 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
361 pfnImport
= reinterpret_cast<FFilterCall
>(
362 aLibrary
.getFunctionSymbol("TestImportWW2"));
365 SvFileStream
aFileStream(out
, StreamMode::READ
);
366 ret
= (int) (*pfnImport
)(aFileStream
);
368 else if (strcmp(argv
[2], "rtf") == 0)
370 static FFilterCall
pfnImport(nullptr);
373 osl::Module aLibrary
;
374 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
375 pfnImport
= reinterpret_cast<FFilterCall
>(
376 aLibrary
.getFunctionSymbol("TestImportRTF"));
379 SvFileStream
aFileStream(out
, StreamMode::READ
);
380 ret
= (int) (*pfnImport
)(aFileStream
);
382 else if ( (strcmp(argv
[2], "xls") == 0) ||
383 (strcmp(argv
[2], "wb2") == 0) )
385 static WFilterCall
pfnImport(nullptr);
388 osl::Module aLibrary
;
389 aLibrary
.loadRelative(&thisModule
, "libscfiltlo.so", SAL_LOADMODULE_LAZY
);
390 pfnImport
= reinterpret_cast<WFilterCall
>(
391 aLibrary
.getFunctionSymbol("TestImportSpreadsheet"));
394 ret
= (int) (*pfnImport
)(out
, OUString(argv
[2], strlen(argv
[2]), RTL_TEXTENCODING_UTF8
));
396 else if (strcmp(argv
[2], "hwp") == 0)
398 static FFilterCall
pfnImport(nullptr);
401 osl::Module aLibrary
;
402 aLibrary
.loadRelative(&thisModule
, "libhwplo.so", SAL_LOADMODULE_LAZY
);
403 pfnImport
= reinterpret_cast<FFilterCall
>(
404 aLibrary
.getFunctionSymbol("TestImportHWP"));
407 SvFileStream
aFileStream(out
, StreamMode::READ
);
408 ret
= (int) (*pfnImport
)(aFileStream
);
410 else if (strcmp(argv
[2], "602") == 0)
412 static FFilterCall
pfnImport(nullptr);
415 osl::Module aLibrary
;
416 aLibrary
.loadRelative(&thisModule
, "libt602filterlo.so", SAL_LOADMODULE_LAZY
);
417 pfnImport
= reinterpret_cast<FFilterCall
>(
418 aLibrary
.getFunctionSymbol("TestImport602"));
421 SvFileStream
aFileStream(out
, StreamMode::READ
);
422 ret
= (int) (*pfnImport
)(aFileStream
);
424 else if (strcmp(argv
[2], "lwp") == 0)
426 static FFilterCall
pfnImport(nullptr);
429 osl::Module aLibrary
;
430 aLibrary
.loadRelative(&thisModule
, "liblwpftlo.so", SAL_LOADMODULE_LAZY
);
431 pfnImport
= reinterpret_cast<FFilterCall
>(
432 aLibrary
.getFunctionSymbol("TestImportLWP"));
435 SvFileStream
aFileStream(out
, StreamMode::READ
);
436 ret
= (int) (*pfnImport
)(aFileStream
);
438 else if (strcmp(argv
[2], "ppt") == 0)
440 static FFilterCall
pfnImport(nullptr);
443 osl::Module aLibrary
;
444 aLibrary
.loadRelative(&thisModule
, "libsdfiltlo.so", SAL_LOADMODULE_LAZY
);
445 pfnImport
= reinterpret_cast<FFilterCall
>(
446 aLibrary
.getFunctionSymbol("TestImportPPT"));
449 SvFileStream
aFileStream(out
, StreamMode::READ
);
450 ret
= (int) (*pfnImport
)(aFileStream
);
452 else if (strcmp(argv
[2], "cgm") == 0)
454 static FFilterCall
pfnImport(nullptr);
457 osl::Module aLibrary
;
458 aLibrary
.loadRelative(&thisModule
, "libsdlo.so", SAL_LOADMODULE_LAZY
);
459 pfnImport
= reinterpret_cast<FFilterCall
>(
460 aLibrary
.getFunctionSymbol("TestImportCGM"));
463 SvFileStream
aFileStream(out
, StreamMode::READ
);
464 ret
= (int) (*pfnImport
)(aFileStream
);
470 /* To signal successful completion of a run, we need to deliver
471 SIGSTOP to our own process, then loop to the very beginning
472 once we're resumed by the supervisor process. We do this only
473 if AFL_PERSISTENT is set to retain normal behavior when the
474 program is executed directly; and take note of PERSIST_MAX. */
475 if (getenv("AFL_PERSISTENT") && persist_cnt
++ < PERSIST_MAX
)
481 /* If AFL_PERSISTENT not set or PERSIST_MAX exceeded, exit normally. */
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */