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:

committed by
Commit Bot

parent
32562250ca
commit
d6c6f16063
@ -15,31 +15,33 @@
|
||||
#include "modules/rtp_rtcp/source/rtp_utility.h"
|
||||
|
||||
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
|
||||
// the RTPExtensionType enum. This assert ensures two bytes are enough.
|
||||
static_assert(kRtpExtensionNumberOfExtensions <= 16,
|
||||
// the RTPExtensionType enum. This assert ensures four bytes are enough.
|
||||
static_assert(kRtpExtensionNumberOfExtensions <= 32,
|
||||
"Insufficient bits read to configure all header extensions. Add "
|
||||
"an extra byte and update the switches.");
|
||||
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
if (size <= 2)
|
||||
if (size <= 4)
|
||||
return;
|
||||
|
||||
// Don't use the configuration byte as part of the packet.
|
||||
std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data));
|
||||
data += 2;
|
||||
size -= 2;
|
||||
std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
RtpPacketReceived::ExtensionManager extensions;
|
||||
// Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid.
|
||||
for (int i = 0; i < kRtpExtensionNumberOfExtensions; i++) {
|
||||
RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true);
|
||||
// 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++) {
|
||||
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
|
||||
// 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.
|
||||
extensions.RegisterByType(i, extension_type);
|
||||
// parsing so the value of the ID isn't relevant.
|
||||
extensions.RegisterByType(local_id++, extension_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,32 +16,33 @@
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
||||
|
||||
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
|
||||
// the RTPExtensionType enum. This assert ensures two bytes are enough.
|
||||
static_assert(kRtpExtensionNumberOfExtensions <= 16,
|
||||
// the RTPExtensionType enum. This assert ensures four bytes are enough.
|
||||
static_assert(kRtpExtensionNumberOfExtensions <= 32,
|
||||
"Insufficient bits read to configure all header extensions. Add "
|
||||
"an extra byte and update the switches.");
|
||||
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
if (size <= 2)
|
||||
if (size <= 4)
|
||||
return;
|
||||
|
||||
// Don't use the configuration bytes as part of the packet.
|
||||
std::bitset<16> extensionMask(*reinterpret_cast<const uint16_t*>(data));
|
||||
data += 2;
|
||||
size -= 2;
|
||||
// Don't use the configuration byte as part of the packet.
|
||||
std::bitset<32> extensionMask(*reinterpret_cast<const uint32_t*>(data));
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
RtpPacketReceived::ExtensionManager extensions;
|
||||
// Skip i = 0 since it maps to ExtensionNone and extension id = 0 is invalid.
|
||||
RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true);
|
||||
// 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++) {
|
||||
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
|
||||
// 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.
|
||||
extensions.RegisterByType(i, extension_type);
|
||||
// parsing so the value of the ID isn't relevant.
|
||||
extensions.RegisterByType(local_id++, extension_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user