diff options
-rw-r--r-- | Android.bp | 7 | ||||
-rw-r--r-- | Android.mk | 110 | ||||
-rw-r--r-- | METADATA | 19 | ||||
-rw-r--r-- | OWNERS.android | 1 | ||||
-rw-r--r-- | fuzz/Android.bp | 24 | ||||
-rw-r--r-- | fuzz/OWNERS | 2 | ||||
-rw-r--r-- | fuzz/mjpeg_dec_fuzz.cc | 139 | ||||
-rwxr-xr-x | setup_env.bat | 7 |
8 files changed, 193 insertions, 116 deletions
@@ -1,13 +1,7 @@ package { default_applicable_licenses: ["external_libyuv_license"], } - // Added automatically by a large-scale-change -// -// large-scale-change included anything that looked like it might be a license -// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. -// -// Please consider removing redundant or irrelevant files from 'license_text:'. // See: http://go/android-license-faq license { name: "external_libyuv_license", @@ -20,6 +14,7 @@ license { "PATENTS", ], } +subdirs = ["files"] cc_library { name: "libyuv", diff --git a/Android.mk b/Android.mk deleted file mode 100644 index ad5e3f62..00000000 --- a/Android.mk +++ /dev/null @@ -1,110 +0,0 @@ -# This is the Android makefile for libyuv for NDK. -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_CPP_EXTENSION := .cc - -LOCAL_SRC_FILES := \ - source/compare.cc \ - source/compare_common.cc \ - source/compare_gcc.cc \ - source/compare_msa.cc \ - source/compare_neon.cc \ - source/compare_neon64.cc \ - source/compare_win.cc \ - source/convert.cc \ - source/convert_argb.cc \ - source/convert_from.cc \ - source/convert_from_argb.cc \ - source/convert_to_argb.cc \ - source/convert_to_i420.cc \ - source/cpu_id.cc \ - source/planar_functions.cc \ - source/rotate.cc \ - source/rotate_any.cc \ - source/rotate_argb.cc \ - source/rotate_common.cc \ - source/rotate_gcc.cc \ - source/rotate_msa.cc \ - source/rotate_neon.cc \ - source/rotate_neon64.cc \ - source/rotate_win.cc \ - source/row_any.cc \ - source/row_common.cc \ - source/row_gcc.cc \ - source/row_msa.cc \ - source/row_neon.cc \ - source/row_neon64.cc \ - source/row_win.cc \ - source/scale.cc \ - source/scale_any.cc \ - source/scale_argb.cc \ - source/scale_common.cc \ - source/scale_gcc.cc \ - source/scale_msa.cc \ - source/scale_neon.cc \ - source/scale_neon64.cc \ - source/scale_rgb.cc \ - source/scale_uv.cc \ - source/scale_win.cc \ - source/video_common.cc - -common_CFLAGS := -Wall -fexceptions -ifneq ($(LIBYUV_DISABLE_JPEG), "yes") -LOCAL_SRC_FILES += \ - source/convert_jpeg.cc \ - source/mjpeg_decoder.cc \ - source/mjpeg_validate.cc -common_CFLAGS += -DHAVE_JPEG -LOCAL_SHARED_LIBRARIES := libjpeg -endif - -LOCAL_CFLAGS += $(common_CFLAGS) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_C_INCLUDES += $(LOCAL_PATH)/include -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include - -LOCAL_MODULE := libyuv_static -LOCAL_MODULE_TAGS := optional - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_WHOLE_STATIC_LIBRARIES := libyuv_static -LOCAL_MODULE := libyuv -ifneq ($(LIBYUV_DISABLE_JPEG), "yes") -LOCAL_SHARED_LIBRARIES := libjpeg -endif - -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_STATIC_LIBRARIES := libyuv_static -LOCAL_SHARED_LIBRARIES := libjpeg -LOCAL_MODULE_TAGS := tests -LOCAL_CPP_EXTENSION := .cc -LOCAL_C_INCLUDES += $(LOCAL_PATH)/include -LOCAL_SRC_FILES := \ - unit_test/basictypes_test.cc \ - unit_test/color_test.cc \ - unit_test/compare_test.cc \ - unit_test/convert_argb_test.cc \ - unit_test/convert_test.cc \ - unit_test/cpu_test.cc \ - unit_test/cpu_thread_test.cc \ - unit_test/math_test.cc \ - unit_test/planar_test.cc \ - unit_test/rotate_argb_test.cc \ - unit_test/rotate_test.cc \ - unit_test/scale_argb_test.cc \ - unit_test/scale_plane_test.cc \ - unit_test/scale_rgb_test.cc \ - unit_test/scale_test.cc \ - unit_test/scale_uv_test.cc \ - unit_test/unit_test.cc \ - unit_test/video_common_test.cc - -LOCAL_MODULE := libyuv_unittest -include $(BUILD_NATIVE_TEST) diff --git a/METADATA b/METADATA new file mode 100644 index 00000000..19d0436e --- /dev/null +++ b/METADATA @@ -0,0 +1,19 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update libyuv +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md + +name: "libyuv" +description: "libyuv is an open source project that includes YUV scaling and conversion functionality." +third_party { + license_type: NOTICE + last_upgrade_date { + year: 2024 + month: 1 + day: 11 + } + identifier { + type: "Git" + value: "https://chromium.googlesource.com/libyuv/libyuv/" + version: "af6ac8265bbd07bcf977526458b60305c4304288" + } +} diff --git a/OWNERS.android b/OWNERS.android new file mode 100644 index 00000000..7529cb92 --- /dev/null +++ b/OWNERS.android @@ -0,0 +1 @@ +include platform/system/core:/janitors/OWNERS diff --git a/fuzz/Android.bp b/fuzz/Android.bp new file mode 100644 index 00000000..a8d552b1 --- /dev/null +++ b/fuzz/Android.bp @@ -0,0 +1,24 @@ + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "external_libyuv_license" + // to get the below license kinds: + // SPDX-license-identifier-BSD + default_applicable_licenses: ["external_libyuv_license"], +} + +cc_fuzz { + name: "libyuv_mjpeg_dec_fuzz", + host_supported: false, + srcs: [ + "mjpeg_dec_fuzz.cc", + ], + static_libs: [ + "libyuv", + ], + + shared_libs: [ + "libjpeg", + ], +} diff --git a/fuzz/OWNERS b/fuzz/OWNERS new file mode 100644 index 00000000..37481f5d --- /dev/null +++ b/fuzz/OWNERS @@ -0,0 +1,2 @@ +ispo@google.com +fbarchard@google.com diff --git a/fuzz/mjpeg_dec_fuzz.cc b/fuzz/mjpeg_dec_fuzz.cc new file mode 100644 index 00000000..3be8410a --- /dev/null +++ b/fuzz/mjpeg_dec_fuzz.cc @@ -0,0 +1,139 @@ +// ----------------------------------------------------------------------------- +// Fuzz Target for libyuv's mjpeg decoder. +// +// This fuzz target focuses on the decoding from JPEG to YUV format. +// ----------------------------------------------------------------------------- +#include "libyuv/basic_types.h" +#include "libyuv/mjpeg_decoder.h" + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <malloc.h> + + +// ----------------------------------------------------------------------------- +// Checks whether 3 values are equal. +// +inline bool IsEqual(int a, int b, int c) { + return (a == b && a == c); +} + +// ----------------------------------------------------------------------------- +// libFuzzer's callback that is invoked upon startup. +// +extern "C" int LLVMFuzzerInitialize(int *unused_argc, char ***unused_argv) { + (void) unused_argc; // Avoid "-Wunused-parameter" warnings. + (void) unused_argv; + // Printing this message is benefial as we can infer which fuzzer runs + // just by looking at the logs which are stored in the cloud. + printf("[*] Fuzz Target for libyuv mjpeg decoder started.\n"); + + return 0; +} + +// ----------------------------------------------------------------------------- +// Decodes a JPEG image into a YUV format. +// +extern "C" bool Decode(libyuv::MJpegDecoder &decoder) { + // YUV colors are represented with one "luminance" component called Y + // and two "chrominance" components, called U and V. + // Planar formats use separate matrices for each of the 3 color components. + // + // If we don't have 3 components abort. + // + // NOTE: It may be possible to have 4 planes for CMYK and alpha, but it's + // very rare and not supported. + int num_planes = decoder.GetNumComponents(); + + if (num_planes != 3) { + return false; + } + + /* NOTE: Without a jpeg corpus, we can't reach this point */ + + int width = decoder.GetWidth(); + int height = decoder.GetHeight(); + int y_width = decoder.GetComponentWidth(0); + int y_height = decoder.GetComponentHeight(0); + int u_width = decoder.GetComponentWidth(1); + int u_height = decoder.GetComponentHeight(1); + int v_width = decoder.GetComponentWidth(2); + int v_height = decoder.GetComponentHeight(2); + uint8_t *y; + uint8_t *u; + uint8_t *v; + + // Make sure that width and heigh stay at decent levels (< 16K * 16K). + // (Y is the largest buffer). + if (width > (1 << 14) || height > (1 << 14)) { + // Ok, if this happens it's a DoS, but let's ignore it for now. + return false; + } + + // Allocate stides according to the sampling type. + if (IsEqual(y_width, u_width, v_width) && + IsEqual(y_height, u_height, v_height)) { + // Sampling type: YUV444. + y = new uint8_t[width * height]; + u = new uint8_t[width * height]; + v = new uint8_t[width * height]; + + } else if (IsEqual((y_width + 1) / 2, u_width, v_width) && + IsEqual(y_height, u_height, v_height)) { + // Sampling type: YUV422. + y = new uint8_t[width * height]; + u = new uint8_t[((width + 1) / 2) * height]; + v = new uint8_t[((width + 1) / 2) * height]; + + } else if (IsEqual((y_width + 1) / 2, u_width, v_width) && + IsEqual((y_height + 1) / 2, u_height, v_height)) { + // Sampling type: YUV420. + y = new uint8_t[width * height]; + u = new uint8_t[((width + 1) / 2) * ((height + 1) / 2)]; + v = new uint8_t[((width + 1) / 2) * ((height + 1) / 2)]; + + } else { + // Invalid sampling type. + return false; + } + + uint8_t* planes[] = {y, u, v}; + + // Do the actual decoding. (Ignore return values). + decoder.DecodeToBuffers(planes, width, height); + + delete[] y; + delete[] u; + delete[] v; + + return true; // Success! +} + +// ----------------------------------------------------------------------------- +// libFuzzer's callback that performs the actual fuzzing. +// +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + // Make sure that we have a minimum length (32 or something small). + if (size < 32) { + return 0; + } + + // Create the decoder object. + libyuv::MJpegDecoder decoder; + + // Load frame, read its headers and determine uncompress image format. + if (decoder.LoadFrame(data, size) == LIBYUV_FALSE) { + // Header parsing error. Discrad frame. + return 0; + } + + // Do the actual decoding. + Decode(decoder); + + // Unload the frame. + decoder.UnloadFrame(); + + return 0; +} diff --git a/setup_env.bat b/setup_env.bat new file mode 100755 index 00000000..d8a33a68 --- /dev/null +++ b/setup_env.bat @@ -0,0 +1,7 @@ +:: This script must not rely on any external tools or PATH values. +@echo OFF + +if "%SETUP_ENV_LIBYUV_TOOLS%"=="done" goto :EOF +set SETUP_ENV_LIBYUV_TOOLS=done + +:: TODO(fbarchard): add files\win32 to for psnr tool |