Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Improve neteq_rtp_fuzzer
Browse files Browse the repository at this point in the history
This change lets the fuzzer modify the first few bytes of the RTP
payload. One of the benefits is that it can cover the RED header
splitter functionality.

The CL also fixes an issue found while running the fuzzer locally.

Bug: webrtc:11640
Change-Id: I7ca73676440897a14a0aaca796f70d381e016575
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185819
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32242}
  • Loading branch information
Henrik Lundin authored and Commit Bot committed Sep 29, 2020
1 parent be0aec2 commit df2a465
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/audio_coding/neteq/red_payload_splitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ bool RedPayloadSplitter::SplitRed(PacketList* packet_list) {
payload_length -= kRedHeaderLength;
}
// Store in new list of packets.
new_headers.push_back(new_header);
if (new_header.payload_length > 0) {
new_headers.push_back(new_header);
}
}

if (new_headers.size() <= kMaxRedBlocks) {
Expand Down
28 changes: 28 additions & 0 deletions test/fuzzers/neteq_rtp_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#include <algorithm>
#include <cmath>
#include <cstring>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -64,6 +66,7 @@ class FuzzRtpInput : public NetEqInput {
std::numeric_limits<int64_t>::max()));
packet_ = input_->PopPacket();
FuzzHeader();
MaybeFuzzPayload();
}

absl::optional<int64_t> NextPacketTime() const override {
Expand All @@ -79,6 +82,7 @@ class FuzzRtpInput : public NetEqInput {
std::unique_ptr<PacketData> packet_to_return = std::move(packet_);
packet_ = input_->PopPacket();
FuzzHeader();
MaybeFuzzPayload();
return packet_to_return;
}

Expand Down Expand Up @@ -116,6 +120,30 @@ class FuzzRtpInput : public NetEqInput {
RTC_CHECK_EQ(data_ix_ - start_ix, kNumBytesToFuzz);
}

void MaybeFuzzPayload() {
// Read one byte of fuzz data to determine how many payload bytes to fuzz.
if (data_ix_ + 1 > data_.size()) {
ended_ = true;
return;
}
size_t bytes_to_fuzz = data_[data_ix_++];

// Restrict number of bytes to fuzz to 16; a reasonably low number enough to
// cover a few RED headers. Also don't write outside the payload length.
bytes_to_fuzz = std::min(bytes_to_fuzz % 16, packet_->payload.size());

if (bytes_to_fuzz == 0)
return;

if (data_ix_ + bytes_to_fuzz > data_.size()) {
ended_ = true;
return;
}

std::memcpy(packet_->payload.data(), &data_[data_ix_], bytes_to_fuzz);
data_ix_ += bytes_to_fuzz;
}

bool ended_ = false;
rtc::ArrayView<const uint8_t> data_;
size_t data_ix_ = 0;
Expand Down

0 comments on commit df2a465

Please sign in to comment.