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 deps = [ 132 ":fuzzer_utils", 133 "../../:pdfium_public_headers", 134 "../../fpdfsdk", 135 ] 136 if (pdf_enable_v8) { 137 configs += [ "//v8:external_startup_data" ] 138 deps += [ 139 "../:test_support", 140 "../../fxjs", 141 "//v8", 142 "//v8:v8_libplatform", 143 ] 144 if (pdf_enable_xfa) { 145 deps += [ ":fuzzer_xfa_process_state" ] 146 } 147 } 148} 149 150if (is_component_build) { 151 group("fuzzer_impls") { 152 testonly = true 153 deps = [] 154 foreach(fuzzer, fuzzer_list) { 155 deps += [ ":${fuzzer}_impl" ] 156 } 157 if (pdf_enable_xfa) { 158 deps += [ ":fuzzer_xfa_process_state" ] 159 } 160 } 161} 162 163source_set("fuzzer_helper") { 164 testonly = !is_component_build 165 sources = [ 166 "pdfium_fuzzer_helper.cc", 167 "pdfium_fuzzer_helper.h", 168 ] 169 configs += [ ":fuzzer_config" ] 170 deps = [ 171 "../../:pdfium_public_headers", 172 "../../fpdfsdk", 173 "../../third_party:pdfium_base", 174 ] 175} 176 177source_set("fuzzer_utils") { 178 # In component builds, the pdfium target (which is not testonly) depends on 179 # the fuzzer sources, which may depend on this target, so add testonly only in 180 # non-component builds. 181 testonly = !is_component_build 182 sources = [ 183 "pdfium_fuzzer_util.cc", 184 "pdfium_fuzzer_util.h", 185 ] 186 deps = [ "../../:pdfium_public_headers" ] 187 include_dirs = [ "../.." ] 188} 189 190template("pdfium_fuzzer") { 191 is_public = defined(invoker.public_fuzzer) && invoker.public_fuzzer 192 if (is_public) { 193 init_dep = ":fuzzer_init_public" 194 } else { 195 init_dep = ":fuzzer_init" 196 } 197 if (is_component_build) { 198 # In component builds, fuzzers are split into "_impl" and "_src" targets. 199 # The "_impl" target exports the fuzzer implementation. The "_src" target 200 # is a thin wrapper that imports the fuzzer from PDFium; this gets linked 201 # into the real fuzzer executable. The real fuzzer target has to depend on 202 # both the "_impl" and "_src" targets. 203 # In static builds, there's only a single "_src" target that contains the 204 # implementation and statically links in PDFium. 205 206 impl_name = target_name + "_impl" 207 template_target_name = target_name 208 source_set("${target_name}_src") { 209 testonly = true 210 sources = [ "component_fuzzer_template.cc" ] 211 deps = [ 212 "../../:pdfium_public_headers", 213 init_dep, 214 ] 215 configs += [ ":fuzzer_config" ] 216 defines = [ "FUZZER_IMPL=${template_target_name}" ] 217 } 218 } else { 219 impl_name = target_name + "_src" 220 } 221 source_set(impl_name) { 222 testonly = true 223 sources = invoker.sources 224 defines = [] 225 deps = [] 226 if (defined(invoker.deps)) { 227 deps += invoker.deps 228 } 229 configs += [ ":fuzzer_config" ] 230 if (is_component_build) { 231 # |export| should be consistent with FPDF_EXPORT In public/fpdfview.h. 232 if (is_win) { 233 export = "__declspec(dllexport)" 234 } else { 235 export = "__attribute__((visibility(\"default\")))" 236 } 237 defines += [ "LLVMFuzzerTestOneInput=${export} ${template_target_name}" ] 238 deps += [ "../../:pdfium_public_headers" ] 239 } else { 240 testonly = true 241 deps += [ 242 "../../:pdfium", 243 init_dep, 244 ] 245 } 246 if (is_public && pdf_enable_xfa) { 247 deps += [ ":fuzzer_xfa_process_state" ] 248 } 249 } 250} 251 252if (pdf_enable_v8) { 253 pdfium_fuzzer("pdf_cjs_util_fuzzer") { 254 sources = [ "pdf_cjs_util_fuzzer.cc" ] 255 deps = [ 256 "../../core/fxcrt", 257 "../../fpdfsdk", 258 "../../fxjs", 259 ] 260 } 261 pdfium_fuzzer("pdf_fx_date_helpers_fuzzer") { 262 sources = [ "pdf_fx_date_helpers_fuzzer.cc" ] 263 deps = [ 264 "../../core/fxcrt", 265 "../../fpdfsdk", 266 "../../fxjs", 267 ] 268 } 269 270 if (pdf_enable_xfa) { 271 pdfium_fuzzer("pdf_bidi_fuzzer") { 272 sources = [ "pdf_bidi_fuzzer.cc" ] 273 deps = [ 274 "../../:freetype_common", 275 "../../core/fxcrt", 276 "../../core/fxge", 277 "../../xfa/fgas/font", 278 "../../xfa/fgas/layout", 279 "//third_party/icu:icuuc", 280 ] 281 } 282 283 pdfium_fuzzer("pdf_cfgas_stringformatter_fuzzer") { 284 sources = [ "pdf_cfgas_stringformatter_fuzzer.cc" ] 285 deps = [ 286 ":fuzzer_utils", 287 "../../core/fxcrt", 288 "../../fpdfsdk", 289 "../../fxjs:gc", 290 "../../xfa/fgas/crt", 291 "../../xfa/fxfa", 292 "../../xfa/fxfa/parser", 293 ] 294 public_fuzzer = true 295 } 296 297 pdfium_fuzzer("pdf_cfx_barcode_fuzzer") { 298 sources = [ "pdf_cfx_barcode_fuzzer.cc" ] 299 deps = [ 300 "../../core/fxcrt", 301 "../../fxbarcode", 302 "//third_party/icu:icuuc", 303 ] 304 } 305 306 if (pdf_enable_xfa_bmp) { 307 pdfium_fuzzer("pdf_codec_bmp_fuzzer") { 308 sources = [ 309 "pdf_codec_bmp_fuzzer.cc", 310 "xfa_codec_fuzzer.h", 311 ] 312 deps = [ 313 "../../core/fxcodec", 314 "../../core/fxcrt", 315 "../../core/fxge", 316 "../../third_party:pdfium_base", 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 "../../third_party:pdfium_base", 332 ] 333 } 334 335 pdfium_fuzzer("pdf_lzw_fuzzer") { 336 sources = [ "pdf_lzw_fuzzer.cc" ] 337 deps = [ 338 "../../core/fxcodec", 339 "../../third_party:pdfium_base", 340 ] 341 } 342 } 343 344 pdfium_fuzzer("pdf_codec_jpeg_fuzzer") { 345 sources = [ 346 "pdf_codec_jpeg_fuzzer.cc", 347 "xfa_codec_fuzzer.h", 348 ] 349 deps = [ 350 "../../core/fxcodec", 351 "../../core/fxcrt", 352 "../../core/fxge", 353 "../../third_party:pdfium_base", 354 ] 355 } 356 357 if (pdf_enable_xfa_png) { 358 pdfium_fuzzer("pdf_codec_png_fuzzer") { 359 sources = [ 360 "pdf_codec_png_fuzzer.cc", 361 "xfa_codec_fuzzer.h", 362 ] 363 deps = [ 364 "../../core/fxcodec", 365 "../../core/fxcrt", 366 "../../core/fxge", 367 "../../third_party:pdfium_base", 368 ] 369 } 370 } 371 372 if (pdf_enable_xfa_tiff) { 373 pdfium_fuzzer("pdf_codec_tiff_fuzzer") { 374 sources = [ 375 "pdf_codec_tiff_fuzzer.cc", 376 "xfa_codec_fuzzer.h", 377 ] 378 deps = [ 379 "../../core/fxcodec", 380 "../../core/fxcrt", 381 "../../core/fxge", 382 "../../third_party:pdfium_base", 383 ] 384 } 385 } 386 387 pdfium_fuzzer("pdf_css_fuzzer") { 388 sources = [ "pdf_css_fuzzer.cc" ] 389 deps = [ 390 "../../core/fxcrt", 391 "../../core/fxcrt/css", 392 ] 393 } 394 395 pdfium_fuzzer("pdf_formcalc_translate_fuzzer") { 396 sources = [ "pdf_formcalc_translate_fuzzer.cc" ] 397 deps = [ 398 ":fuzzer_utils", 399 "../../core/fxcrt", 400 "../../fpdfsdk", 401 "../../fxjs", 402 ] 403 public_fuzzer = true 404 } 405 406 pdfium_fuzzer("pdf_formcalc_context_fuzzer") { 407 sources = [ "pdf_formcalc_context_fuzzer.cc" ] 408 deps = [ 409 ":fuzzer_helper", 410 "../../:pdfium_public_headers", 411 "../../core/fxcrt", 412 "../../fpdfsdk", 413 "../../fpdfsdk/fpdfxfa", 414 "../../fxjs", 415 "../../xfa/fxfa", 416 ] 417 public_fuzzer = true 418 } 419 420 pdfium_fuzzer("pdf_formcalc_fuzzer") { 421 sources = [ "pdf_formcalc_fuzzer.cc" ] 422 deps = [ 423 ":fuzzer_utils", 424 "../../core/fxcrt", 425 "../../fxjs:gc", 426 "../../xfa/fxfa/formcalc", 427 ] 428 public_fuzzer = true 429 } 430 431 pdfium_fuzzer("pdfium_xfa_fuzzer") { 432 sources = [ "pdfium_xfa_fuzzer.cc" ] 433 deps = [ 434 ":fuzzer_helper", 435 "../../:pdfium_public_headers", 436 ] 437 public_fuzzer = true 438 } 439 440 pdfium_fuzzer("pdfium_xfa_lpm_fuzzer") { 441 sources = [ 442 "pdfium_xfa_lpm_fuzz_stub.cc", 443 "pdfium_xfa_lpm_fuzz_stub.h", 444 ] 445 deps = [ 446 ":fuzzer_helper", 447 "../../:pdfium_public_headers", 448 ] 449 public_fuzzer = true 450 } 451 } 452} 453 454if (is_clang) { 455 pdfium_fuzzer("pdf_cpdf_tounicodemap_fuzzer") { 456 sources = [ "pdf_cpdf_tounicodemap_fuzzer.cc" ] 457 deps = [ 458 "../../core/fpdfapi/font", 459 "../../core/fpdfapi/parser", 460 "../../core/fxcrt", 461 ] 462 } 463 464 pdfium_fuzzer("pdf_nametree_fuzzer") { 465 sources = [ "pdf_nametree_fuzzer.cc" ] 466 deps = [ 467 "../../core/fpdfapi/page", 468 "../../core/fpdfapi/parser", 469 "../../core/fpdfdoc", 470 "../../third_party:pdfium_base", 471 ] 472 } 473 if (pdf_enable_xfa) { 474 pdfium_fuzzer("pdf_xfa_fdp_fuzzer") { 475 sources = [ "pdf_xfa_fdp_fuzzer.cc" ] 476 deps = [ 477 ":fuzzer_helper", 478 ":fuzzer_pdf_templates", 479 "../../third_party:pdfium_base", 480 ] 481 public_fuzzer = true 482 } 483 pdfium_fuzzer("pdf_xfa_raw_fuzzer") { 484 sources = [ "pdf_xfa_raw_fuzzer.cc" ] 485 deps = [ 486 ":fuzzer_helper", 487 ":fuzzer_pdf_templates", 488 "../../third_party:pdfium_base", 489 ] 490 public_fuzzer = true 491 } 492 pdfium_fuzzer("pdf_xfa_xdp_fdp_fuzzer") { 493 sources = [ "pdf_xfa_xdp_fdp_fuzzer.cc" ] 494 deps = [ 495 ":fuzzer_helper", 496 ":fuzzer_pdf_templates", 497 ] 498 public_fuzzer = true 499 } 500 } 501} 502 503pdfium_fuzzer("pdf_cmap_fuzzer") { 504 sources = [ "pdf_cmap_fuzzer.cc" ] 505 deps = [ 506 "../../:freetype_common", 507 "../../core/fpdfapi/font", 508 "../../core/fxcrt", 509 "../../third_party:pdfium_base", 510 ] 511} 512 513pdfium_fuzzer("pdf_codec_a85_fuzzer") { 514 sources = [ "pdf_codec_a85_fuzzer.cc" ] 515 deps = [ 516 "../../core/fxcodec", 517 "../../core/fxcrt", 518 ] 519} 520 521pdfium_fuzzer("pdf_codec_fax_fuzzer") { 522 sources = [ "pdf_codec_fax_fuzzer.cc" ] 523 deps = [ 524 ":fuzzer_utils", 525 "../../core/fxcodec", 526 ] 527} 528 529pdfium_fuzzer("pdf_codec_icc_fuzzer") { 530 sources = [ "pdf_codec_icc_fuzzer.cc" ] 531 deps = [ 532 "../../core/fxcodec", 533 "../../third_party:pdfium_base", 534 "../../third_party/:lcms2", 535 ] 536} 537 538pdfium_fuzzer("pdf_codec_jbig2_fuzzer") { 539 sources = [ "pdf_codec_jbig2_fuzzer.cc" ] 540 deps = [ 541 ":fuzzer_utils", 542 "../../core/fpdfapi/parser", 543 "../../core/fxcodec", 544 "../../core/fxcrt", 545 "../../core/fxge", 546 ] 547} 548 549pdfium_fuzzer("pdf_codec_rle_fuzzer") { 550 sources = [ "pdf_codec_rle_fuzzer.cc" ] 551 deps = [ 552 "../../core/fxcodec", 553 "../../core/fxcrt", 554 ] 555} 556 557pdfium_fuzzer("pdf_font_fuzzer") { 558 sources = [ "pdf_font_fuzzer.cc" ] 559 deps = [ "../../:pdfium_public_headers" ] 560} 561 562pdfium_fuzzer("pdf_hint_table_fuzzer") { 563 sources = [ "pdf_hint_table_fuzzer.cc" ] 564 deps = [ 565 "../../core/fpdfapi/parser", 566 "../../core/fxcrt", 567 "../../third_party:pdfium_base", 568 ] 569} 570 571pdfium_fuzzer("pdf_jpx_fuzzer") { 572 sources = [ "pdf_jpx_fuzzer.cc" ] 573 deps = [ 574 "../../core/fpdfapi/page", 575 "../../core/fxcodec", 576 "../../core/fxcrt", 577 "../../core/fxge", 578 ] 579} 580 581pdfium_fuzzer("pdf_psengine_fuzzer") { 582 sources = [ "pdf_psengine_fuzzer.cc" ] 583 deps = [ 584 "../../core/fpdfapi/page", 585 "../../third_party:pdfium_base", 586 ] 587} 588 589pdfium_fuzzer("pdf_scanlinecompositor_fuzzer") { 590 sources = [ "pdf_scanlinecompositor_fuzzer.cc" ] 591 deps = [ 592 ":fuzzer_utils", 593 "../../core/fxcrt", 594 "../../core/fxge", 595 "../../third_party:pdfium_base", 596 ] 597} 598 599pdfium_fuzzer("pdf_streamparser_fuzzer") { 600 sources = [ "pdf_streamparser_fuzzer.cc" ] 601 deps = [ 602 "../../core/fpdfapi/page", 603 "../../core/fpdfapi/parser", 604 "../../third_party:pdfium_base", 605 ] 606} 607 608pdfium_fuzzer("pdf_xml_fuzzer") { 609 sources = [ "pdf_xml_fuzzer.cc" ] 610 deps = [ 611 "../../core/fxcrt", 612 "../../third_party:pdfium_base", 613 ] 614} 615 616pdfium_fuzzer("pdfium_fuzzer") { 617 sources = [ "pdfium_fuzzer.cc" ] 618 deps = [ ":fuzzer_helper" ] 619 public_fuzzer = true 620} 621