Add AEC3 config json parsing fuzzer

Bug: webrtc:9535
Change-Id: Ic659a31b6d5b26a07aee955a5b83e889122b4705
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157306
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29520}
diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn
index 7e4e545..2768ad4 100644
--- a/test/fuzzers/BUILD.gn
+++ b/test/fuzzers/BUILD.gn
@@ -524,6 +524,19 @@
   seed_corpus = "corpora/agc-corpus"
 }
 
+webrtc_fuzzer_test("aec3_config_json_fuzzer") {
+  sources = [
+    "aec3_config_json_fuzzer.cc",
+  ]
+  deps = [
+    ":fuzz_data_helper",
+    "../../api/audio:aec3_config",
+    "../../api/audio:aec3_config_json",
+  ]
+  dict = "//testing/libfuzzer/fuzzers/dicts/json.dict"
+  seed_corpus = "corpora/aec3-config-json-corpus"
+}
+
 webrtc_fuzzer_test("comfort_noise_decoder_fuzzer") {
   sources = [
     "comfort_noise_decoder_fuzzer.cc",
diff --git a/test/fuzzers/aec3_config_json_fuzzer.cc b/test/fuzzers/aec3_config_json_fuzzer.cc
new file mode 100644
index 0000000..626350c
--- /dev/null
+++ b/test/fuzzers/aec3_config_json_fuzzer.cc
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <string>
+
+#include "api/audio/echo_canceller3_config.h"
+#include "api/audio/echo_canceller3_config_json.h"
+#include "test/fuzzers/fuzz_data_helper.h"
+
+namespace webrtc {
+void FuzzOneInput(const uint8_t* data, size_t size) {
+  if (size > 10000) {
+    return;
+  }
+  std::string config_json(reinterpret_cast<const char*>(data), size);
+
+  EchoCanceller3Config config;
+  bool success;
+  Aec3ConfigFromJsonString(config_json, &config, &success);
+  EchoCanceller3Config::Validate(&config);
+}
+
+}  // namespace webrtc
diff --git a/test/fuzzers/corpora/aec3-config-json-corpus/default.json b/test/fuzzers/corpora/aec3-config-json-corpus/default.json
new file mode 100644
index 0000000..4dcbcee
--- /dev/null
+++ b/test/fuzzers/corpora/aec3-config-json-corpus/default.json
@@ -0,0 +1 @@
+{"aec3": {"buffering": {"excess_render_detection_interval_blocks": 250,"max_allowed_excess_render_blocks": 8},"delay": {"default_delay": 5,"down_sampling_factor": 4,"num_filters": 5,"delay_headroom_samples": 32,"hysteresis_limit_blocks": 1,"fixed_capture_delay_samples": 0,"delay_estimate_smoothing": 0.7,"delay_candidate_detection_threshold": 0.2,"delay_selection_thresholds": {"initial": 5,"converged": 20},"use_external_delay_estimator": false,"downmix_before_delay_estimation": true,"log_warning_on_delay_changes": false},"filter": {"main": [13,5e-05,0.05,0.001,2,2.00753e+07],"shadow": [13,0.7,2.00753e+07],"main_initial": [12,0.005,0.5,0.001,2,2.00753e+07],"shadow_initial": [12,0.9,2.00753e+07],"config_change_duration_blocks": 250,"initial_state_seconds": 2.5,"conservative_initial_phase": false,"enable_shadow_filter_output_usage": true},"erle": {"min": 1,"max_l": 4,"max_h": 1.5,"onset_detection": true,"num_sections": 1,"clamp_quality_estimate_to_zero": true,"clamp_quality_estimate_to_one": true},"ep_strength": {"default_gain": 1,"default_len": 0.83,"echo_can_saturate": true,"bounded_erl": false},"echo_audibility": {"low_render_limit": 256,"normal_render_limit": 64,"floor_power": 128,"audibility_threshold_lf": 10,"audibility_threshold_mf": 10,"audibility_threshold_hf": 10,"use_stationarity_properties": false,"use_stationarity_properties_at_init": false},"render_levels": {"active_render_limit": 100,"poor_excitation_render_limit": 150,"poor_excitation_render_limit_ds8": 20},"echo_removal_control": {"has_clock_drift": false,"linear_and_stable_echo_path": false},"echo_model": {"noise_floor_hold": 50,"min_noise_floor_power": 1.6384e+06,"stationary_gate_slope": 10,"noise_gate_power": 27509.4,"noise_gate_slope": 0.3,"render_pre_window_size": 1,"render_post_window_size": 1},"suppressor": {"nearend_average_blocks": 4,"normal_tuning": {"mask_lf": [0.3,0.4,0.3],"mask_hf": [0.07,0.1,0.3],"max_inc_factor": 2,"max_dec_factor_lf": 0.25},"nearend_tuning": {"mask_lf": [1.09,1.1,0.3],"mask_hf": [0.1,0.3,0.3],"max_inc_factor": 2,"max_dec_factor_lf": 0.25},"dominant_nearend_detection": {"enr_threshold": 0.25,"enr_exit_threshold": 10,"snr_threshold": 30,"hold_duration": 50,"trigger_threshold": 12,"use_during_initial_phase": 1},"high_bands_suppression": {"enr_threshold": 1,"max_gain_during_echo": 1},"floor_first_increase": 1e-05,"enforce_transparent": false,"enforce_empty_higher_bands": false}}}