Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: webrtc/test/fuzzers/audio_decoder_fuzzer.cc

Issue 1499093002: Create fuzzer tests for audio decoders (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add a public_configs element to webrtc_fuzzer_main Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/test/fuzzers/audio_decoder_fuzzer.cc
diff --git a/webrtc/test/fuzzers/audio_decoder_fuzzer.cc b/webrtc/test/fuzzers/audio_decoder_fuzzer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fb5adb6cd8e55ca236138a00e762d75b5151cde5
--- /dev/null
+++ b/webrtc/test/fuzzers/audio_decoder_fuzzer.cc
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 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 "webrtc/test/fuzzers/audio_decoder_fuzzer.h"
+
+#include "webrtc/base/checks.h"
+#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
+
+namespace webrtc {
+namespace {
+size_t PacketSizeFromTwoBytes(const uint8_t* data, size_t size) {
+ if (size < 2)
+ return 0;
+ return static_cast<size_t>((data[0] << 8) + data[1]);
+}
+} // namespace
+
+// This function reads two bytes from the beginning of |data|, interprets them
+// as the first packet length, and reads this many bytes if available. The
+// payload is inserted into the decoder, and the process continues until no more
+// data is available.
+void FuzzAudioDecoder(const uint8_t* data,
+ size_t size,
+ AudioDecoder* decoder,
+ int sample_rate_hz,
+ size_t max_decoded_bytes,
+ int16_t* decoded) {
+ const uint8_t* data_ptr = data;
+ size_t remaining_size = size;
+ size_t packet_len = PacketSizeFromTwoBytes(data_ptr, remaining_size);
+ while (packet_len != 0 && packet_len <= remaining_size - 2) {
+ data_ptr += 2;
+ remaining_size -= 2;
+ AudioDecoder::SpeechType speech_type;
+ decoder->Decode(data_ptr, packet_len, sample_rate_hz, max_decoded_bytes,
+ decoded, &speech_type);
+ data_ptr += packet_len;
+ remaining_size -= packet_len;
+ packet_len = PacketSizeFromTwoBytes(data_ptr, remaining_size);
+ }
+}
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698