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