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>
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 extern "C" { static void SAL_CALL
thisModule() {} }
67 typedef bool (*WFilterCall
)(const OUString
&rUrl
, const OUString
&rFlt
);
68 typedef bool (*HFilterCall
)(const OUString
&rUrl
);
70 /* This constant specifies the number of inputs to process before restarting.
71 * This is optional, but helps limit the impact of memory leaks and similar
74 #define PERSIST_MAX 1000
75 unsigned int persist_cnt
;
77 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
84 fprintf(stderr
, "Usage: fftester <filename> <wmf|jpg>\n");
88 OUString
in(argv
[1], strlen(argv
[1]), RTL_TEXTENCODING_UTF8
);
90 osl::File::getFileURLFromSystemPath(in
, out
);
92 tools::extendApplicationEnvironment();
94 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
95 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
96 if( !xServiceManager
.is() )
97 Application::Abort( "Failed to bootstrap" );
98 comphelper::setProcessServiceFactory( xServiceManager
);
99 utl::ConfigManager::EnableAvoidConfig();
105 if (strcmp(argv
[2], "wmf") == 0 || strcmp(argv
[2], "emf") == 0)
107 GDIMetaFile aGDIMetaFile
;
108 SvFileStream
aFileStream(out
, StreamMode::READ
);
109 ret
= (int) ReadWindowMetafile(aFileStream
, aGDIMetaFile
);
111 (void)aGDIMetaFile
.CreateThumbnail(aTarget
);
113 else if (strcmp(argv
[2], "jpg") == 0)
116 SvFileStream
aFileStream(out
, StreamMode::READ
);
117 ret
= (int) ImportJPEG(aFileStream
, aGraphic
, nullptr, GraphicFilterImportFlags::NONE
);
118 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
119 aTarget
.Convert(BmpConversion::N24Bit
);
121 else if (strcmp(argv
[2], "gif") == 0)
123 SvFileStream
aFileStream(out
, StreamMode::READ
);
125 ret
= (int) ImportGIF(aFileStream
, aGraphic
);
126 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
127 aTarget
.Convert(BmpConversion::N24Bit
);
129 else if (strcmp(argv
[2], "xbm") == 0)
132 SvFileStream
aFileStream(out
, StreamMode::READ
);
133 ret
= (int) ImportXBM(aFileStream
, aGraphic
);
134 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
135 aTarget
.Convert(BmpConversion::N24Bit
);
137 else if (strcmp(argv
[2], "xpm") == 0)
140 SvFileStream
aFileStream(out
, StreamMode::READ
);
141 ret
= (int) ImportXPM(aFileStream
, aGraphic
);
142 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
143 aTarget
.Convert(BmpConversion::N24Bit
);
145 else if (strcmp(argv
[2], "png") == 0)
147 SvFileStream
aFileStream(out
, StreamMode::READ
);
148 vcl::PNGReader
aReader(aFileStream
);
149 BitmapEx aTarget
= aReader
.Read();
150 aTarget
.Convert(BmpConversion::N24Bit
);
152 else if (strcmp(argv
[2], "bmp") == 0)
155 SvFileStream
aFileStream(out
, StreamMode::READ
);
156 ret
= (int) ReadDIB(aTarget
, aFileStream
, true);
157 aTarget
.Convert(BmpConversion::N24Bit
);
159 else if (strcmp(argv
[2], "svm") == 0)
161 GDIMetaFile aGDIMetaFile
;
162 SvFileStream
aFileStream(out
, StreamMode::READ
);
163 ReadGDIMetaFile(aFileStream
, aGDIMetaFile
);
165 else if (strcmp(argv
[2], "pcd") == 0)
167 static PFilterCall
pfnImport(nullptr);
170 osl::Module aLibrary
;
171 aLibrary
.loadRelative(&thisModule
, "libicdlo.so");
172 pfnImport
= reinterpret_cast<PFilterCall
>(
173 aLibrary
.getFunctionSymbol("GraphicImport"));
177 SvFileStream
aFileStream(out
, StreamMode::READ
);
178 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
179 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
180 aTarget
.Convert(BmpConversion::N24Bit
);
182 else if (strcmp(argv
[2], "dxf") == 0)
184 static PFilterCall
pfnImport(nullptr);
187 osl::Module aLibrary
;
188 aLibrary
.loadRelative(&thisModule
, "libidxlo.so");
189 pfnImport
= reinterpret_cast<PFilterCall
>(
190 aLibrary
.getFunctionSymbol("GraphicImport"));
194 SvFileStream
aFileStream(out
, StreamMode::READ
);
195 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
196 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
197 aTarget
.Convert(BmpConversion::N24Bit
);
199 else if (strcmp(argv
[2], "met") == 0)
201 static PFilterCall
pfnImport(nullptr);
204 osl::Module aLibrary
;
205 aLibrary
.loadRelative(&thisModule
, "libimelo.so");
206 pfnImport
= reinterpret_cast<PFilterCall
>(
207 aLibrary
.getFunctionSymbol("GraphicImport"));
211 SvFileStream
aFileStream(out
, StreamMode::READ
);
212 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
213 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
214 aTarget
.Convert(BmpConversion::N24Bit
);
216 else if ((strcmp(argv
[2], "pbm") == 0) || strcmp(argv
[2], "ppm") == 0)
218 static PFilterCall
pfnImport(nullptr);
221 osl::Module aLibrary
;
222 aLibrary
.loadRelative(&thisModule
, "libipblo.so");
223 pfnImport
= reinterpret_cast<PFilterCall
>(
224 aLibrary
.getFunctionSymbol("GraphicImport"));
228 SvFileStream
aFileStream(out
, StreamMode::READ
);
229 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
230 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
231 aTarget
.Convert(BmpConversion::N24Bit
);
233 else if (strcmp(argv
[2], "psd") == 0)
235 static PFilterCall
pfnImport(nullptr);
238 osl::Module aLibrary
;
239 aLibrary
.loadRelative(&thisModule
, "libipdlo.so");
240 pfnImport
= reinterpret_cast<PFilterCall
>(
241 aLibrary
.getFunctionSymbol("GraphicImport"));
245 SvFileStream
aFileStream(out
, StreamMode::READ
);
246 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
247 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
248 aTarget
.Convert(BmpConversion::N24Bit
);
250 else if (strcmp(argv
[2], "eps") == 0)
252 static PFilterCall
pfnImport(nullptr);
255 osl::Module aLibrary
;
256 aLibrary
.loadRelative(&thisModule
, "libipslo.so");
257 pfnImport
= reinterpret_cast<PFilterCall
>(
258 aLibrary
.getFunctionSymbol("GraphicImport"));
262 SvFileStream
aFileStream(out
, StreamMode::READ
);
263 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
264 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
265 aTarget
.Convert(BmpConversion::N24Bit
);
267 else if (strcmp(argv
[2], "pct") == 0)
269 static PFilterCall
pfnImport(nullptr);
272 osl::Module aLibrary
;
273 aLibrary
.loadRelative(&thisModule
, "libiptlo.so");
274 pfnImport
= reinterpret_cast<PFilterCall
>(
275 aLibrary
.getFunctionSymbol("GraphicImport"));
279 SvFileStream
aFileStream(out
, StreamMode::READ
);
280 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
281 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
282 aTarget
.Convert(BmpConversion::N24Bit
);
284 else if (strcmp(argv
[2], "pcx") == 0)
286 static PFilterCall
pfnImport(nullptr);
289 osl::Module aLibrary
;
290 aLibrary
.loadRelative(&thisModule
, "libipxlo.so");
291 pfnImport
= reinterpret_cast<PFilterCall
>(
292 aLibrary
.getFunctionSymbol("GraphicImport"));
296 SvFileStream
aFileStream(out
, StreamMode::READ
);
297 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
298 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
299 aTarget
.Convert(BmpConversion::N24Bit
);
301 else if (strcmp(argv
[2], "ras") == 0)
303 static PFilterCall
pfnImport(nullptr);
306 osl::Module aLibrary
;
307 aLibrary
.loadRelative(&thisModule
, "libiralo.so");
308 pfnImport
= reinterpret_cast<PFilterCall
>(
309 aLibrary
.getFunctionSymbol("GraphicImport"));
313 SvFileStream
aFileStream(out
, StreamMode::READ
);
314 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
315 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
316 aTarget
.Convert(BmpConversion::N24Bit
);
318 else if (strcmp(argv
[2], "tga") == 0)
320 static PFilterCall
pfnImport(nullptr);
323 osl::Module aLibrary
;
324 aLibrary
.loadRelative(&thisModule
, "libitglo.so");
325 pfnImport
= reinterpret_cast<PFilterCall
>(
326 aLibrary
.getFunctionSymbol("GraphicImport"));
330 SvFileStream
aFileStream(out
, StreamMode::READ
);
331 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
332 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
333 aTarget
.Convert(BmpConversion::N24Bit
);
335 else if (strcmp(argv
[2], "tif") == 0)
337 static PFilterCall
pfnImport(nullptr);
340 osl::Module aLibrary
;
341 aLibrary
.loadRelative(&thisModule
, "libitilo.so");
342 pfnImport
= reinterpret_cast<PFilterCall
>(
343 aLibrary
.getFunctionSymbol("GraphicImport"));
347 SvFileStream
aFileStream(out
, StreamMode::READ
);
348 ret
= (int) (*pfnImport
)(aFileStream
, aGraphic
, nullptr);
349 BitmapEx aTarget
= aGraphic
.GetBitmapEx();
350 aTarget
.Convert(BmpConversion::N24Bit
);
352 else if ( (strcmp(argv
[2], "doc") == 0) ||
353 (strcmp(argv
[2], "ww8") == 0) ||
354 (strcmp(argv
[2], "ww6") == 0) ||
355 (strcmp(argv
[2], "ww2") == 0) )
357 static WFilterCall
pfnImport(nullptr);
360 osl::Module aLibrary
;
361 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
362 pfnImport
= reinterpret_cast<WFilterCall
>(
363 aLibrary
.getFunctionSymbol("TestImportDOC"));
366 if (strcmp(argv
[2], "ww6") == 0)
367 ret
= (int) (*pfnImport
)(out
, OUString("CWW6"));
368 else if (strcmp(argv
[2], "ww2") == 0)
369 ret
= (int) (*pfnImport
)(out
, OUString("WW6"));
371 ret
= (int) (*pfnImport
)(out
, OUString("CWW8"));
373 else if (strcmp(argv
[2], "rtf") == 0)
375 static HFilterCall
pfnImport(nullptr);
378 osl::Module aLibrary
;
379 aLibrary
.loadRelative(&thisModule
, "libmswordlo.so", SAL_LOADMODULE_LAZY
);
380 pfnImport
= reinterpret_cast<HFilterCall
>(
381 aLibrary
.getFunctionSymbol("TestImportRTF"));
384 ret
= (int) (*pfnImport
)(out
);
386 else if ( (strcmp(argv
[2], "xls") == 0) ||
387 (strcmp(argv
[2], "wb2") == 0) )
389 static WFilterCall
pfnImport(nullptr);
392 osl::Module aLibrary
;
393 aLibrary
.loadRelative(&thisModule
, "libscfiltlo.so", SAL_LOADMODULE_LAZY
);
394 pfnImport
= reinterpret_cast<WFilterCall
>(
395 aLibrary
.getFunctionSymbol("TestImportSpreadsheet"));
398 ret
= (int) (*pfnImport
)(out
, OUString(argv
[2], strlen(argv
[2]), RTL_TEXTENCODING_UTF8
));
400 else if (strcmp(argv
[2], "hwp") == 0)
402 static HFilterCall
pfnImport(nullptr);
405 osl::Module aLibrary
;
406 aLibrary
.loadRelative(&thisModule
, "libhwplo.so", SAL_LOADMODULE_LAZY
);
407 pfnImport
= reinterpret_cast<HFilterCall
>(
408 aLibrary
.getFunctionSymbol("TestImportHWP"));
411 ret
= (int) (*pfnImport
)(out
);
413 else if (strcmp(argv
[2], "602") == 0)
415 static HFilterCall
pfnImport(nullptr);
418 osl::Module aLibrary
;
419 aLibrary
.loadRelative(&thisModule
, "libt602filterlo.so", SAL_LOADMODULE_LAZY
);
420 pfnImport
= reinterpret_cast<HFilterCall
>(
421 aLibrary
.getFunctionSymbol("TestImport602"));
424 ret
= (int) (*pfnImport
)(out
);
426 else if (strcmp(argv
[2], "lwp") == 0)
428 static HFilterCall
pfnImport(nullptr);
431 osl::Module aLibrary
;
432 aLibrary
.loadRelative(&thisModule
, "liblwpftlo.so", SAL_LOADMODULE_LAZY
);
433 pfnImport
= reinterpret_cast<HFilterCall
>(
434 aLibrary
.getFunctionSymbol("TestImportLWP"));
437 ret
= (int) (*pfnImport
)(out
);
439 else if (strcmp(argv
[2], "ppt") == 0)
441 static HFilterCall
pfnImport(nullptr);
444 osl::Module aLibrary
;
445 aLibrary
.loadRelative(&thisModule
, "libsdfiltlo.so", SAL_LOADMODULE_LAZY
);
446 pfnImport
= reinterpret_cast<HFilterCall
>(
447 aLibrary
.getFunctionSymbol("TestImportPPT"));
450 ret
= (int) (*pfnImport
)(out
);
454 /* To signal successful completion of a run, we need to deliver
455 SIGSTOP to our own process, then loop to the very beginning
456 once we're resumed by the supervisor process. We do this only
457 if AFL_PERSISTENT is set to retain normal behavior when the
458 program is executed directly; and take note of PERSIST_MAX. */
459 if (getenv("AFL_PERSISTENT") && persist_cnt
++ < PERSIST_MAX
)
465 /* If AFL_PERSISTENT not set or PERSIST_MAX exceeded, exit normally. */
475 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */