1# Copyright 2016 The PDFium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("../../pdfium.gni") 6 7config("fuzzer_config") { 8 configs = [ "../..:pdfium_core_config" ] 9 10 defines = [ 11 "PNG_PREFIX", 12 "PNG_USE_READ_MACROS", 13 ] 14 include_dirs = [ "../.." ] 15} 16 17# All possible "pdfium_fuzzer"s. 18fuzzer_list = [ 19 "pdf_cmap_fuzzer", 20 "pdf_codec_a85_fuzzer", 21 "pdf_codec_fax_fuzzer", 22 "pdf_codec_icc_fuzzer", 23 "pdf_codec_jbig2_fuzzer", 24 "pdf_codec_rle_fuzzer", 25 "pdf_font_fuzzer", 26 "pdf_hint_table_fuzzer", 27 "pdf_jpx_fuzzer", 28 "pdf_psengine_fuzzer", 29 "pdf_scanlinecompositor_fuzzer", 30 "pdf_streamparser_fuzzer", 31 "pdf_xml_fuzzer", 32 "pdfium_fuzzer", 33] 34if (pdf_enable_v8) { 35 fuzzer_list += [ 36 "pdf_cjs_util_fuzzer", 37 "pdf_fx_date_helpers_fuzzer", 38 ] 39 if (pdf_enable_xfa) { 40 fuzzer_list += [ 41 "pdf_bidi_fuzzer", 42 "pdf_cfgas_stringformatter_fuzzer", 43 "pdf_cfx_barcode_fuzzer", 44 "pdf_codec_jpeg_fuzzer", 45 "pdf_css_fuzzer", 46 "pdf_fm2js_fuzzer", 47 "pdf_formcalc_context_fuzzer", 48 "pdf_formcalc_fuzzer", 49 "pdfium_xfa_fuzzer", 50 "pdfium_xfa_lpm_fuzzer", 51 ] 52 if (pdf_enable_xfa_bmp) { 53 fuzzer_list += [ "pdf_codec_bmp_fuzzer" ] 54 } 55 if (pdf_enable_xfa_gif) { 56 fuzzer_list += [ 57 "pdf_codec_gif_fuzzer", 58 "pdf_lzw_fuzzer", 59 ] 60 } 61 if (pdf_enable_xfa_png) { 62 fuzzer_list += [ "pdf_codec_png_fuzzer" ] 63 } 64 if (pdf_enable_xfa_tiff) { 65 fuzzer_list += [ "pdf_codec_tiff_fuzzer" ] 66 } 67 } 68} 69if (is_clang) { 70 # Fuzzers that use FuzzedDataProvider can only be built with Clang. 71 fuzzer_list += [ "pdf_nametree_fuzzer" ] 72} 73 74group("fuzzers") { 75 testonly = true 76 deps = [] 77 foreach(fuzzer, fuzzer_list) { 78 deps += [ ":${fuzzer}_src" ] 79 } 80} 81 82source_set("fuzzer_init") { 83 testonly = true 84 sources = [ "pdf_fuzzer_init.cc" ] 85 include_dirs = [ "../.." ] 86 deps = [ "../../:pdfium_public_headers" ] 87} 88 89source_set("fuzzer_init_public") { 90 testonly = true 91 sources = [ "pdf_fuzzer_init_public.cc" ] 92 include_dirs = [ "../.." ] 93 deps = [ "../../:pdfium_public_headers" ] 94 if (pdf_enable_v8) { 95 configs += [ "//v8:external_startup_data" ] 96 deps += [ 97 "../:test_support", 98 "//v8", 99 "//v8:v8_libplatform", 100 ] 101 } 102} 103 104if (is_component_build) { 105 group("fuzzer_impls") { 106 deps = [] 107 foreach(fuzzer, fuzzer_list) { 108 deps += [ ":${fuzzer}_impl" ] 109 } 110 } 111} 112 113source_set("fuzzer_helper") { 114 testonly = !is_component_build 115 sources = [ 116 "pdfium_fuzzer_helper.cc", 117 "pdfium_fuzzer_helper.h", 118 ] 119 configs += [ ":fuzzer_config" ] 120 deps = [ 121 "../../:pdfium_public_headers", 122 "../../third_party:pdfium_base", 123 ] 124} 125 126source_set("fuzzer_utils") { 127 # In component builds, the pdfium target (which is not testonly) depends on 128 # the fuzzer sources, which may depend on this target, so add testonly only in 129 # non-component builds. 130 testonly = !is_component_build 131 sources = [ 132 "pdfium_fuzzer_util.cc", 133 "pdfium_fuzzer_util.h", 134 ] 135 deps = [ "../../:pdfium_public_headers" ] 136 include_dirs = [ "../.." ] 137} 138 139template("pdfium_fuzzer") { 140 if (defined(invoker.public_fuzzer) && invoker.public_fuzzer) { 141 init_dep = ":fuzzer_init_public" 142 } else { 143 init_dep = ":fuzzer_init" 144 } 145 if (is_component_build) { 146 # In component builds, fuzzers are split into "_impl" and "_src" targets. 147 # The "_impl" target exports the fuzzer implementation and gets statically 148 # linked into the PDFium shared library. The "_src" target is a thin 149 # wrapper that imports the fuzzer from PDFium; this gets linked into the 150 # real fuzzer executable. In static builds, there's only a single "_src" 151 # target that contains the implementation and statically links in PDFium. 152 153 impl_name = target_name + "_impl" 154 template_target_name = target_name 155 source_set("${target_name}_src") { 156 testonly = true 157 sources = [ "component_fuzzer_template.cc" ] 158 deps = [ 159 "../../:pdfium", 160 init_dep, 161 ] 162 configs += [ ":fuzzer_config" ] 163 defines = [ "FUZZER_IMPL=${template_target_name}" ] 164 } 165 } else { 166 impl_name = target_name + "_src" 167 } 168 source_set(impl_name) { 169 sources = invoker.sources 170 deps = [] 171 if (defined(invoker.deps)) { 172 deps += invoker.deps 173 } 174 configs -= [ "//build/config/compiler:chromium_code" ] 175 configs += [ 176 "//build/config/compiler:no_chromium_code", 177 ":fuzzer_config", 178 ] 179 if (is_component_build) { 180 # |export| should be consistent with FPDF_EXPORT In public/fpdfview.h. 181 if (is_win) { 182 export = "__declspec(dllexport)" 183 } else { 184 export = "__attribute__((visibility(\"default\")))" 185 } 186 defines = [ "LLVMFuzzerTestOneInput=${export} ${template_target_name}" ] 187 deps += [ "../../:pdfium_public_headers" ] 188 } else { 189 testonly = true 190 deps += [ 191 "../../:pdfium", 192 init_dep, 193 ] 194 } 195 } 196} 197 198if (pdf_enable_v8) { 199 pdfium_fuzzer("pdf_cjs_util_fuzzer") { 200 sources = [ "pdf_cjs_util_fuzzer.cc" ] 201 deps = [ 202 "../../core/fxcrt", 203 "../../fxjs", 204 ] 205 } 206 pdfium_fuzzer("pdf_fx_date_helpers_fuzzer") { 207 sources = [ "pdf_fx_date_helpers_fuzzer.cc" ] 208 deps = [ 209 "../../core/fxcrt", 210 "../../fxjs", 211 ] 212 } 213 214 if (pdf_enable_xfa) { 215 pdfium_fuzzer("pdf_bidi_fuzzer") { 216 sources = [ "pdf_bidi_fuzzer.cc" ] 217 deps = [ 218 "../../:freetype_common", 219 "../../core/fxcrt", 220 "../../core/fxge", 221 "../../xfa/fgas", 222 "../../xfa/fgas/layout", 223 "//third_party/icu:icuuc", 224 ] 225 } 226 227 pdfium_fuzzer("pdf_cfgas_stringformatter_fuzzer") { 228 sources = [ "pdf_cfgas_stringformatter_fuzzer.cc" ] 229 deps = [ 230 "../../core/fxcrt", 231 "../../xfa/fgas", 232 "../../xfa/fxfa/parser", 233 ] 234 } 235 236 pdfium_fuzzer("pdf_cfx_barcode_fuzzer") { 237 sources = [ "pdf_cfx_barcode_fuzzer.cc" ] 238 deps = [ 239 "../../core/fxcrt", 240 "../../fxbarcode", 241 "//third_party/icu:icuuc", 242 ] 243 } 244 245 if (pdf_enable_xfa_bmp) { 246 pdfium_fuzzer("pdf_codec_bmp_fuzzer") { 247 sources = [ 248 "pdf_codec_bmp_fuzzer.cc", 249 "xfa_codec_fuzzer.h", 250 ] 251 deps = [ 252 "../../core/fxcodec", 253 "../../core/fxcrt", 254 "../../core/fxge", 255 "../../third_party:pdfium_base", 256 ] 257 } 258 } 259 260 if (pdf_enable_xfa_gif) { 261 pdfium_fuzzer("pdf_codec_gif_fuzzer") { 262 sources = [ 263 "pdf_codec_gif_fuzzer.cc", 264 "xfa_codec_fuzzer.h", 265 ] 266 deps = [ 267 "../../core/fxcodec", 268 "../../core/fxcrt", 269 "../../core/fxge", 270 "../../third_party:pdfium_base", 271 ] 272 } 273 274 pdfium_fuzzer("pdf_lzw_fuzzer") { 275 sources = [ "pdf_lzw_fuzzer.cc" ] 276 deps = [ 277 "../../core/fxcodec", 278 "../../third_party:pdfium_base", 279 ] 280 } 281 } 282 283 pdfium_fuzzer("pdf_codec_jpeg_fuzzer") { 284 sources = [ 285 "pdf_codec_jpeg_fuzzer.cc", 286 "xfa_codec_fuzzer.h", 287 ] 288 deps = [ 289 "../../core/fxcodec", 290 "../../core/fxcrt", 291 "../../core/fxge", 292 "../../third_party:pdfium_base", 293 ] 294 } 295 296 if (pdf_enable_xfa_png) { 297 pdfium_fuzzer("pdf_codec_png_fuzzer") { 298 sources = [ 299 "pdf_codec_png_fuzzer.cc", 300 "xfa_codec_fuzzer.h", 301 ] 302 deps = [ 303 "../../core/fxcodec", 304 "../../core/fxcrt", 305 "../../core/fxge", 306 "../../third_party:pdfium_base", 307 ] 308 } 309 } 310 311 if (pdf_enable_xfa_tiff) { 312 pdfium_fuzzer("pdf_codec_tiff_fuzzer") { 313 sources = [ 314 "pdf_codec_tiff_fuzzer.cc", 315 "xfa_codec_fuzzer.h", 316 ] 317 deps = [ 318 "../../core/fxcodec", 319 "../../core/fxcrt", 320 "../../core/fxge", 321 "../../third_party:pdfium_base", 322 ] 323 } 324 } 325 326 pdfium_fuzzer("pdf_css_fuzzer") { 327 sources = [ "pdf_css_fuzzer.cc" ] 328 deps = [ 329 "../../core/fxcrt", 330 "../../core/fxcrt/css", 331 ] 332 } 333 334 pdfium_fuzzer("pdf_fm2js_fuzzer") { 335 sources = [ "pdf_fm2js_fuzzer.cc" ] 336 deps = [ 337 "../../core/fxcrt", 338 "../../fxjs", 339 ] 340 } 341 342 pdfium_fuzzer("pdf_formcalc_context_fuzzer") { 343 sources = [ "pdf_formcalc_context_fuzzer.cc" ] 344 deps = [ 345 ":fuzzer_helper", 346 "../../:pdfium_public_headers", 347 "../../core/fxcrt", 348 "../../fpdfsdk", 349 "../../fpdfsdk/fpdfxfa", 350 "../../fxjs", 351 "../../xfa/fxfa", 352 ] 353 public_fuzzer = true 354 } 355 356 pdfium_fuzzer("pdf_formcalc_fuzzer") { 357 sources = [ "pdf_formcalc_fuzzer.cc" ] 358 deps = [ 359 "../../core/fxcrt", 360 "../../xfa/fxfa/fm2js", 361 ] 362 } 363 364 pdfium_fuzzer("pdfium_xfa_fuzzer") { 365 sources = [ "pdfium_xfa_fuzzer.cc" ] 366 deps = [ 367 ":fuzzer_helper", 368 "../../:pdfium_public_headers", 369 ] 370 public_fuzzer = true 371 } 372 373 pdfium_fuzzer("pdfium_xfa_lpm_fuzzer") { 374 sources = [ 375 "pdfium_xfa_lpm_fuzz_stub.cc", 376 "pdfium_xfa_lpm_fuzz_stub.h", 377 ] 378 deps = [ 379 ":fuzzer_helper", 380 "../../:pdfium_public_headers", 381 ] 382 public_fuzzer = true 383 } 384 } 385} 386 387if (is_clang) { 388 pdfium_fuzzer("pdf_nametree_fuzzer") { 389 sources = [ "pdf_nametree_fuzzer.cc" ] 390 deps = [ 391 "../../core/fpdfapi/page", 392 "../../core/fpdfapi/parser", 393 "../../core/fpdfdoc", 394 "../../third_party:pdfium_base", 395 ] 396 } 397} 398 399pdfium_fuzzer("pdf_cmap_fuzzer") { 400 sources = [ "pdf_cmap_fuzzer.cc" ] 401 deps = [ 402 "../../:freetype_common", 403 "../../core/fpdfapi/font", 404 "../../third_party:pdfium_base", 405 ] 406} 407 408pdfium_fuzzer("pdf_codec_a85_fuzzer") { 409 sources = [ "pdf_codec_a85_fuzzer.cc" ] 410 deps = [ 411 "../../core/fxcodec", 412 "../../core/fxcrt", 413 ] 414} 415 416pdfium_fuzzer("pdf_codec_fax_fuzzer") { 417 sources = [ "pdf_codec_fax_fuzzer.cc" ] 418 deps = [ 419 ":fuzzer_utils", 420 "../../core/fxcodec", 421 ] 422} 423 424pdfium_fuzzer("pdf_codec_icc_fuzzer") { 425 sources = [ "pdf_codec_icc_fuzzer.cc" ] 426 deps = [ 427 "../../core/fxcodec", 428 "../../third_party:pdfium_base", 429 "../../third_party/:lcms2", 430 ] 431} 432 433pdfium_fuzzer("pdf_codec_jbig2_fuzzer") { 434 sources = [ "pdf_codec_jbig2_fuzzer.cc" ] 435 deps = [ 436 ":fuzzer_utils", 437 "../../core/fpdfapi/parser", 438 "../../core/fxcodec", 439 "../../core/fxcrt", 440 "../../core/fxge", 441 ] 442} 443 444pdfium_fuzzer("pdf_codec_rle_fuzzer") { 445 sources = [ "pdf_codec_rle_fuzzer.cc" ] 446 deps = [ 447 "../../core/fxcodec", 448 "../../core/fxcrt", 449 ] 450} 451 452pdfium_fuzzer("pdf_font_fuzzer") { 453 sources = [ "pdf_font_fuzzer.cc" ] 454 deps = [ "../../:pdfium_public_headers" ] 455} 456 457pdfium_fuzzer("pdf_hint_table_fuzzer") { 458 sources = [ "pdf_hint_table_fuzzer.cc" ] 459 deps = [ 460 "../../core/fpdfapi/parser", 461 "../../core/fxcrt", 462 "../../third_party:pdfium_base", 463 ] 464} 465 466pdfium_fuzzer("pdf_jpx_fuzzer") { 467 sources = [ "pdf_jpx_fuzzer.cc" ] 468 deps = [ 469 "../../core/fpdfapi/page", 470 "../../core/fxcodec", 471 "../../core/fxcrt", 472 "../../core/fxge", 473 ] 474} 475 476pdfium_fuzzer("pdf_psengine_fuzzer") { 477 sources = [ "pdf_psengine_fuzzer.cc" ] 478 deps = [ 479 "../../core/fpdfapi/page", 480 "../../third_party:pdfium_base", 481 ] 482} 483 484pdfium_fuzzer("pdf_scanlinecompositor_fuzzer") { 485 sources = [ "pdf_scanlinecompositor_fuzzer.cc" ] 486 deps = [ 487 ":fuzzer_utils", 488 "../../core/fxge", 489 "../../third_party:pdfium_base", 490 ] 491} 492 493pdfium_fuzzer("pdf_streamparser_fuzzer") { 494 sources = [ "pdf_streamparser_fuzzer.cc" ] 495 deps = [ 496 "../../core/fpdfapi/page", 497 "../../core/fpdfapi/parser", 498 "../../third_party:pdfium_base", 499 ] 500} 501 502pdfium_fuzzer("pdf_xml_fuzzer") { 503 sources = [ "pdf_xml_fuzzer.cc" ] 504 deps = [ 505 "../../core/fxcrt", 506 "../../third_party:pdfium_base", 507 ] 508} 509 510pdfium_fuzzer("pdfium_fuzzer") { 511 sources = [ "pdfium_fuzzer.cc" ] 512 deps = [ ":fuzzer_helper" ] 513 public_fuzzer = true 514} 515