Update RTP packet and header fuzzers to support additional extensions

Bug: webrtc:10262
Change-Id: I0a089329edc43dc004c616933ae8606a41546865
Reviewed-on: https://webrtc-review.googlesource.com/c/123524
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26793}
This commit is contained in:
Johannes Kron
2019-02-21 09:33:14 +01:00
committed by Commit Bot
parent 32562250ca
commit d6c6f16063
2 changed files with 30 additions and 27 deletions

View File

@ -15,31 +15,33 @@
#include "modules/rtp_rtcp/source/rtp_utility.h" #include "modules/rtp_rtcp/source/rtp_utility.h"
namespace webrtc { namespace webrtc {
// We decide which header extensions to register by reading two bytes // We decide which header extensions to register by reading four bytes
// from the beginning of |data| and interpreting it as a bitmask over // from the beginning of |data| and interpreting it as a bitmask over
// the RTPExtensionType enum. This assert ensures two bytes are enough. // the RTPExtensionType enum. This assert ensures four bytes are enough.
static_assert(kRtpExtensionNumberOfExtensions <= 16, static_assert(kRtpExtensionNumberOfExtensions <= 32,
"Insufficient bits read to configure all header extensions. Add " "Insufficient bits read to configure all header extensions. Add "
"an extra byte and update the switches."); "an extra byte and update the switches.");
void FuzzOneInput(const uint8_t* data, size_t size) { void FuzzOneInput(const uint8_t* data, size_t size) {
if (size <= 2) if (size <= 4)
return; return;
// Don't use the configuration byte as part of the packet. // Don't use the configuration byte as part of the packet.
std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data)); std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
data += 2; data += 4;
size -= 2; size -= 4;
RtpPacketReceived::ExtensionManager extensions; RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true);
// Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid. // Start at local_id = 1 since 0 is an invalid extension id.
for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) { int local_id = 1;
// Skip i = 0 since it maps to kRtpExtensionNone.
for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) {
RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
if (extensionMask[i] && extension_type != kRtpExtensionNone) { if (extensionMask[i]) {
// Extensions are registered with an ID, which you signal to the // Extensions are registered with an ID, which you signal to the
// peer so they know what to expect. This code only cares about // peer so they know what to expect. This code only cares about
// parsing so the value of the ID isn't relevant; we use i. // parsing so the value of the ID isn't relevant.
extensions.RegisterByType(i, extension_type); extensions.RegisterByType(local_id++, extension_type);
} }
} }

View File

@ -16,32 +16,33 @@
#include "modules/rtp_rtcp/source/rtp_packet_received.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h"
namespace webrtc { namespace webrtc {
// We decide which header extensions to register by reading four bytes
// We decide which header extensions to register by reading two bytes
// from the beginning of |data| and interpreting it as a bitmask over // from the beginning of |data| and interpreting it as a bitmask over
// the RTPExtensionType enum. This assert ensures two bytes are enough. // the RTPExtensionType enum. This assert ensures four bytes are enough.
static_assert(kRtpExtensionNumberOfExtensions <= 16, static_assert(kRtpExtensionNumberOfExtensions <= 32,
"Insufficient bits read to configure all header extensions. Add " "Insufficient bits read to configure all header extensions. Add "
"an extra byte and update the switches."); "an extra byte and update the switches.");
void FuzzOneInput(const uint8_t* data, size_t size) { void FuzzOneInput(const uint8_t* data, size_t size) {
if (size <= 2) if (size <= 4)
return; return;
// Don't use the configuration bytes as part of the packet. // Don't use the configuration byte as part of the packet.
std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data)); std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
data += 2; data += 4;
size -= 2; size -= 4;
RtpPacketReceived::ExtensionManager extensions; RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true);
// Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid. // Start at local_id = 1 since 0 is an invalid extension id.
int local_id = 1;
// Skip i = 0 since it maps to kRtpExtensionNone.
for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) { for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) {
RTPExtensionType extension_type = static_cast<RTPExtensionType>(i); RTPExtensionType extension_type = static_cast<RTPExtensionType>(i);
if (extensionMask[i] && extension_type != kRtpExtensionNone) { if (extensionMask[i]) {
// Extensions are registered with an ID, which you signal to the // Extensions are registered with an ID, which you signal to the
// peer so they know what to expect. This code only cares about // peer so they know what to expect. This code only cares about
// parsing so the value of the ID isn't relevant; we use i. // parsing so the value of the ID isn't relevant.
extensions.RegisterByType(i, extension_type); extensions.RegisterByType(local_id++, extension_type);
} }
} }