webrtc_m130/test/fuzzers/rtp_header_parser_fuzzer.cc
Benjamin Wright 1295b0def0 Add basic fuzzing for rtp_header_parser.h/cc.
rtp_header_parser currently has 0% fuzzing coverage. To improve this I have
added a basic fuzzer which fuzzes all of the available paths.

Bug: webrtc:10395
Change-Id: I30324b2bfa7629b0110527258b33b7e048e89fcf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/127040
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27115}
2019-03-13 23:31:16 +00:00

47 lines
1.5 KiB
C++

/*
* 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 <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
namespace webrtc {
void FuzzOneInput(const uint8_t* data, size_t size) {
RtpHeaderParser::IsRtcp(data, size);
RtpHeaderParser::GetSsrc(data, size);
RTPHeader rtp_header;
std::unique_ptr<RtpHeaderParser> rtp_header_parser(RtpHeaderParser::Create());
rtp_header_parser->Parse(data, size, &rtp_header);
for (int i = 1; i < kRtpExtensionNumberOfExtensions; ++i) {
if (size > 0 && i >= data[size - 1]) {
RTPExtensionType add_extension = static_cast<RTPExtensionType>(i);
rtp_header_parser->RegisterRtpHeaderExtension(add_extension, i);
}
}
rtp_header_parser->Parse(data, size, &rtp_header);
for (int i = 1; i < kRtpExtensionNumberOfExtensions; ++i) {
if (size > 1 && i >= data[size - 2]) {
RTPExtensionType remove_extension = static_cast<RTPExtensionType>(i);
rtp_header_parser->DeregisterRtpHeaderExtension(remove_extension);
}
}
rtp_header_parser->Parse(data, size, &rtp_header);
}
} // namespace webrtc