# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//media/media_options.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
# Public configuration exported to users of the libavif target.
config("avif_public_config") {
defines = [ "AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP" ]
if (is_component_build) {
defines += [ "AVIF_DLL" ]
}
}
# Private configuration used in building libavif.
config("avif_config") {
include_dirs = [ "src/include/" ]
defines = [ "AVIF_LIBYUV_ENABLED" ]
if (is_component_build) {
defines += [ "AVIF_BUILDING_SHARED_LIBS" ]
}
if (enable_dav1d_decoder) {
include_dirs += [ "../dav1d/libdav1d/include/" ]
defines += [ "AVIF_CODEC_DAV1D" ]
}
}
libavif_decoder_sources = [
"src/include/avif/internal.h",
"src/src/alpha.c",
"src/src/avif.c",
"src/src/colr.c",
"src/src/diag.c",
"src/src/exif.c",
"src/src/io.c",
"src/src/mem.c",
"src/src/obu.c",
"src/src/rawdata.c",
"src/src/read.c",
"src/src/reformat.c",
"src/src/reformat_libsharpyuv.c",
"src/src/reformat_libyuv.c",
"src/src/scale.c",
"src/src/stream.c",
"src/src/utils.c",
]
component("libavif") {
public = [ "src/include/avif/avif.h" ]
public_configs = [ ":avif_public_config" ]
sources = libavif_decoder_sources
configs += [ ":avif_config" ]
deps = [ "//third_party/libyuv" ]
if (enable_dav1d_decoder) {
sources += [ "src/src/codec_dav1d.c" ]
deps += [ "//third_party/dav1d" ]
}
}
# Note only the decoder fuzzers are enabled as only the decoder is being used
# in Chrome. avif_fuzztest_read_image is not enabled due to libpng not having
# PNG_READ_iTXt_SUPPORTED enabled.
config("avif_fuzztest_config") {
include_dirs = [
"src/include",
"src/apps/shared",
]
}
# This is used to satisfy dependencies in avif_fuzztest_helpers. The encoder
# functions are not used.
component("libavif_enc") {
public = [ "src/include/avif/avif.h" ]
public_configs = [ ":avif_public_config" ]
sources = libavif_decoder_sources + [ "src/src/write.c" ]
testonly = true
configs += [ ":avif_config" ]
deps = [
"//third_party/libwebp:libwebp_sharpyuv",
"//third_party/libyuv",
]
defines = [ "AVIF_LIBSHARPYUV_ENABLED" ]
if (enable_dav1d_decoder) {
sources += [ "src/src/codec_dav1d.c" ]
deps += [ "//third_party/dav1d" ]
}
}
source_set("avif_apps_shared") {
sources = [
"avif_apps_shared_stubs.c",
"src/apps/shared/avifjpeg.h",
"src/apps/shared/avifpng.h",
"src/apps/shared/avifutil.c",
"src/apps/shared/avifutil.h",
"src/apps/shared/y4m.c",
"src/apps/shared/y4m.h",
]
testonly = true
configs += [ ":avif_fuzztest_config" ]
deps = [ ":libavif_enc" ]
}
source_set("avif_fuzztest_helpers") {
sources = [
"src/tests/gtest/avif_fuzztest_helpers.cc",
"src/tests/gtest/avifincrtest_helpers.cc",
"src/tests/gtest/aviftest_helpers.cc",
]
testonly = true
configs += [ ":avif_fuzztest_config" ]
deps = [
":avif_apps_shared",
":libavif_enc",
"//testing/gtest",
"//third_party/fuzztest:fuzztest",
]
}
# TODO: b/308013905 - These tests require seeds from
# third_party/libavif/src/tests/data which
# aren't available in the fuzzing environment. These targets can be enabled if
# they are made hermetic.
#
# test("avif_fuzztest_dec") {
# sources = [ "src/tests/gtest/avif_fuzztest_dec.cc" ]
# fuzztests = [ "DecodeAvifTest.Decode" ]
# configs += [ ":avif_fuzztest_config" ]
# deps = [
# ":avif_fuzztest_helpers",
# ":libavif_enc",
# "//third_party/fuzztest:fuzztest_gtest_main",
# ]
# }
#
# test("avif_fuzztest_dec_incr") {
# sources = [ "src/tests/gtest/avif_fuzztest_dec_incr.cc" ]
# fuzztests = [ "DecodeAvifFuzzTest.DecodeIncr" ]
# configs += [ ":avif_fuzztest_config" ]
# deps = [
# ":avif_fuzztest_helpers",
# ":libavif_enc",
# "//third_party/fuzztest:fuzztest_gtest_main",
# ]
# }
test("avif_fuzztest_yuvrgb") {
sources = [ "src/tests/gtest/avif_fuzztest_yuvrgb.cc" ]
fuzztests = [ "YuvRgbFuzzTest.Convert" ]
configs += [ ":avif_fuzztest_config" ]
deps = [
":avif_fuzztest_helpers",
":libavif_enc",
"//third_party/fuzztest:fuzztest_gtest_main",
]
}