tree: abd6a4779926f8976eb91b7da8a26fc16bd1f81c [path history] [tgz]
  1. Android.bp
  2. avc_dec_fuzzer.cpp
  3. avc_dec_fuzzer.dict
  4. avc_enc_fuzzer.cpp
  5. ossfuzz.sh
  6. README.md
fuzzer/README.md

Fuzzer for libavc decoder

This describes steps to build avc_dec_fuzzer binary.

Linux x86/x64

Requirements

  • cmake (3.5 or above)
  • make
  • clang (6.0 or above) needs to support -fsanitize=fuzzer, -fsanitize=fuzzer-no-link

Steps to build

Clone libavc repository

$ git clone https://android.googlesource.com/platform/external/libavc

Create a directory inside libavc and change directory

 $ cd libavc
 $ mkdir build
 $ cd build

Build libavc using cmake

 $ CC=clang CXX=clang++ cmake ../ \
   -DSANITIZE=fuzzer-no-link,address,signed-integer-overflow
 $ make

Build the fuzzer

 $ clang++ -std=c++11 -fsanitize=fuzzer,address -I.  -I../  -I../common \
   -I../decoder -Wl,--start-group ../fuzzer/avc_dec_fuzzer.cpp \
   -o ./avc_dec_fuzzer ./libavcdec.a -Wl,--end-group

Steps to run

Create a directory CORPUS_DIR and copy some elementary h264 files to that folder To run the fuzzer

$ ./avc_dec_fuzzer CORPUS_DIR

Android

Steps to build

Build the fuzzer

  $ SANITIZE_TARGET=address SANITIZE_HOST=address mmma -j$(nproc) \
    external/libavc/fuzzer

Steps to run

Create a directory CORPUS_DIR and copy some elementary h264 files to that folder Push this directory to device.

To run on device

  $ adb sync data
  $ adb shell /data/fuzz/avc_dec_fuzzer CORPUS_DIR

To run on host

  $ $ANDROID_HOST_OUT/fuzz/avc_dec_fuzzer CORPUS_DIR

Fuzzer for libavc encoder

Plugin Design Considerations

The fuzzer plugin for AVC is designed based on the understanding of the codec and tries to achieve the following:

Maximize code coverage

The configuration parameters are not hardcoded, but instead selected based on incoming data. This ensures more code paths are reached by the fuzzer.

AVC supports the following parameters:

  1. Frame Width (parameter name: u4_wd)
  2. Frame Height (parameter name: u4_ht)
  3. Input color format (parameter name: e_inp_color_fmt)
  4. Architecture type (parameter name: e_arch)
  5. Rate control mode (parameter name: e_rc_mode)
  6. Number of cores (parameter name: u4_num_cores)
  7. Maximum B frames (parameter name: u4_num_bframes)
  8. Encoder speed preset (parameter name: u4_enc_speed_preset)
  9. enable constrained intra prediction (parameter name: u4_constrained_intra_pred)
  10. enable intra 4x4 (parameter name: u4_enable_intra_4x4)
  11. Qp for I frames (parameter name: u4_i_qp)
  12. Qp for P frames (parameter name: u4_p_qp)
  13. Qp for B frames (parameter name: u4_b_qp)
  14. Target Bitrate (parameter name: u4_target_bitrate)
  15. Intra refresh period in frames (parameter name: u4_air_refresh_period)
  16. Enable half pel ME (parameter name: u4_enable_hpel)
  17. Enable quarter pel ME (parameter name: u4_enable_qpel)
  18. ME speed preset (parameter name: u4_me_speed_preset)
  19. Adaptive intra refresh mode (parameter name: e_air_mode)
  20. Disable deblock level (parameter name: u4_disable_deblock_level)
  21. Max search range in X direction (parameter name: u4_srch_rng_x)
  22. Max search range in Y direction (parameter name: u4_srch_rng_y)
  23. I frame interval (parameter name: u4_i_frm_interval)
  24. IDR frame interval (parameter name: u4_idr_frm_interval)
  25. Enable mastering display color volume info (parameter name: u1_sei_mdcv_params_present_flag)
  26. Enable content light level info (parameter name: u1_sei_cll_params_present_flag)
  27. Enable ambient viewing environment info (parameter name: u1_sei_ave_params_present_flag)
  28. Enable content color volume info (parameter name: u1_sei_ccv_params_present_flag)
  29. Profile (parameter name: e_profile)
  30. Enable aspect_ratio info (parameter name: u1_aspect_ratio_info_present_flag)
  31. Enable NAL HRD parameters presence (parameter name: u1_nal_hrd_parameters_present_flag)
  32. Enable VCL HRD parameters presence (parameter name: u1_vcl_hrd_parameters_present_flag)
  33. Enable force IDR frame (parameter name: mIsForceIdrEnabled)
  34. Enable dynamic bitrate change (parameter name: mIsDynamicBitRateChangeEnabled)
  35. Enable dynamic framerate change (parameter name: mIsDynamicFrameRateChangeEnabled)
  36. Force IDR frame number (parameter name: mForceIdrInterval)
  37. Frame number for dynamic bitrate (parameter name: mDynamicBitRateInterval)
  38. Frame number for dynamic framerate (parameter name: mDynamicFrameRateInterval)
ParameterValid ValuesConfigured Value
u4_wdIn the range 0 to 10239All the bits of 1st and 2nd byte of data
u4_htIn the range 0 to 10239All the bits of 3rd and 4th byte of data
e_inp_color_fmt0. IV_YUV_420P 1. IV_YUV_420SP_UV 2. IV_YUV_422ILE 3. IV_YUV_420SP_VUAll the bits of 5th byte of data
e_arch0. ARCH_ARM_NONEON 1. ARCH_NAbit 0 and 1 of 6th byte of data
e_rc_mode0. IVE_RC_NONE 1. IVE_RC_STORAGE 2. IVE_RC_CBR_NON_LOW_DELAY 3. IVE_RC_CBR_LOW_DELAYAll the bits of 7th byte of data modulus 4
u4_num_cores0. 0 1. 1 2. 2 3. 3bit 0 and 1 of 8th byte of data
u4_num_bframesIn the range 0 to 7bit 0, 1 and 2 of 9th byte of data
u4_enc_speed_preset0. IVE_CONFIG 1. IVE_SLOWEST 2. IVE_NORMAL 3. IVE_FAST 4. IVE_HIGH_SPEED 5. IVE_FASTESTAll the bits of 10th byte of data modulus 6
u4_constrained_intra_pred0. 0 1. 1bit 0 of 11th byte of data
u4_enable_intra_4x40. 0 1. 1bit 0 of 12th byte of data
u4_i_qpIn the range 4 to 51All the bits of 13th byte of data
u4_p_qpIn the range 4 to 51All the bits of 14th byte of data
u4_b_qpIn the range 4 to 51All the bits of 15th byte of data
u4_target_bitrateIn the range 0 to 500000000All the bits of 16th and 17th byte of data
u4_target_bitrateIn the range 0 to 255All the bits of 18th byte of data
u4_air_refresh_periodIn the range 1 to 256All the bits of 19th byte of data
u4_air_refresh_periodIn the range 1 to 256All the bits of 19th byte of data
u4_enable_hpel0. 0 1. 1bit 0 of 20th byte of data
u4_enable_qpel0. 0 1. 1bit 0 of 21st byte of data
u4_me_speed_preset0. 0 1. 50 2. 75 3. 100All the bits of 22nd byte of data modulus 4
e_air_mode0. IVE_AIR_MODE_NONE 1. IVE_AIR_MODE_CYCLIC 2. IVE_AIR_MODE_RANDOMAll the bits of 23rd byte of data modulus 3
u4_disable_deblock_level0. 0 1. 1 2. 2 3. 3bit 0 and 1 of 24th byte of data
u4_srch_rng_xIn the range 0 to 255All the bits of 25th byte of data
u4_srch_rng_yIn the range 0 to 255All the bits of 26th byte of data
u4_i_frm_intervalIn the range 1 to 256All the bits of 27th byte of data
u4_idr_frm_intervalIn the range 1 to 256All the bits of 28th byte of data
u1_sei_mdcv_params_present_flag0. 0 1. 1bit 0 of 29th byte of data
u1_sei_cll_params_present_flag0. 0 1. 1bit 0 of 30th byte of data
u1_sei_ave_params_present_flag0. 0 1. 1bit 0 of 31st byte of data
u1_sei_ccv_params_present_flag0. 0 1. 1bit 0 of 32nd byte of data
e_profile0. IV_PROFILE_BASE 1. IV_PROFILE_MAINbit 0 and 1 of 33th byte of data modulus 2
u1_aspect_ratio_info_present_flag0. 0 1. 1bit 0 of 34th byte of data
u1_nal_hrd_parameters_present_flag0. 0 1. 1bit 0 of 35th byte of data
u1_vcl_hrd_parameters_present_flag0. 0 1. 1bit 0 of 36th byte of data
mIsForceIdrEnabled0. 0 1. 1bit 0 of 37th byte of data
mIsDynamicBitRateChangeEnabled0. 0 1. 1bit 0 of 38th byte of data
mIsDynamicFrameRateChangeEnabled0. 0 1. 1bit 0 of 39th byte of data
mForceIdrIntervalIn the range 0 to 7bit 0, 1 and 2 of 40th byte of data
mDynamicBitRateIntervalIn the range 0 to 7bit 0, 1 and 2 of 41st byte of data
mDynamicFrameRateIntervalIn the range 0 to 7bit 0, 1 and 2 of 42nd byte of data

This also ensures that the plugin is always deterministic for any given input.

Maximize utilization of input data

The plugin feeds the entire input data to the codec using a loop. If the encode operation was successful, the input is advanced by the frame size. If the encode operation was un-successful, the input is still advanced by frame size so that the fuzzer can proceed to feed the next frame.

This ensures that the plugin tolerates any kind of input (empty, huge, malformed, etc) and doesnt exit() on any input and thereby increasing the chance of identifying vulnerabilities.

Build

This describes steps to build avc_enc_fuzzer binary.

Android

Steps to build

Build the fuzzer

  $ mm -j$(nproc) avc_enc_fuzzer

Steps to run

Create a directory CORPUS_DIR and copy some yuv files to that folder Push this directory to device.

To run on device

  $ adb sync data
  $ adb shell /data/fuzz/arm64/avc_enc_fuzzer/avc_enc_fuzzer CORPUS_DIR

To run on host

  $ $ANDROID_HOST_OUT/fuzz/x86_64/avc_enc_fuzzer/avc_enc_fuzzer CORPUS_DIR

References: