提交 6a48da76 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

WIP: failing fuzzer for RtpPacket::SetOneByteHeaderExtension() and SetTwoBytesHeaderExtension()

上级 43a55121
...@@ -11,7 +11,9 @@ void Fuzzer::RTC::RtpPacket::Fuzz(const uint8_t* data, size_t len) ...@@ -11,7 +11,9 @@ void Fuzzer::RTC::RtpPacket::Fuzz(const uint8_t* data, size_t len)
// We need to clone the given data into a separate buffer because setters // We need to clone the given data into a separate buffer because setters
// below will try to write into packet memory. // below will try to write into packet memory.
uint8_t data2[len]; //
// NOTE: Let's make the buffer bigger to test API that increases packet size.
uint8_t data2[len + 16];
uint8_t extenLen; uint8_t extenLen;
bool voice; bool voice;
uint8_t volume; uint8_t volume;
...@@ -94,7 +96,10 @@ void Fuzzer::RTC::RtpPacket::Fuzz(const uint8_t* data, size_t len) ...@@ -94,7 +96,10 @@ void Fuzzer::RTC::RtpPacket::Fuzz(const uint8_t* data, size_t len)
packet->GetPayloadPadding(); packet->GetPayloadPadding();
packet->IsKeyFrame(); packet->IsKeyFrame();
uint8_t buffer[len]; packet->SetOneByteHeaderExtension();
packet->SetTwoBytesHeaderExtension();
uint8_t buffer[len + 16];
auto* clonedPacket = packet->Clone(buffer); auto* clonedPacket = packet->Clone(buffer);
delete clonedPacket; delete clonedPacket;
......
...@@ -477,7 +477,7 @@ namespace RTC ...@@ -477,7 +477,7 @@ namespace RTC
inline uint8_t* RtpPacket::GetPayload() const inline uint8_t* RtpPacket::GetPayload() const
{ {
return this->payload; return this->payloadLength != 0 ? this->payload : nullptr;
} }
inline size_t RtpPacket::GetPayloadLength() const inline size_t RtpPacket::GetPayloadLength() const
......
...@@ -286,6 +286,8 @@ namespace RTC ...@@ -286,6 +286,8 @@ namespace RTC
return false; return false;
} }
MS_ERROR("---------- YES 1 !!!");
// Set the header extension bit. // Set the header extension bit.
this->header->extension = 1u; this->header->extension = 1u;
...@@ -296,10 +298,10 @@ namespace RTC ...@@ -296,10 +298,10 @@ namespace RTC
std::memmove(this->payload + 4, this->payload, this->payloadLength + this->payloadPadding); std::memmove(this->payload + 4, this->payload, this->payloadLength + this->payloadPadding);
this->payload += 4; this->payload += 4;
// Increase size. // Increase packet total size.
this->size += 4; this->size += 4;
// Set the header extension id and length. // Set the header extension id with length 0.
this->headerExtension->id = uint16_t{ htons(0xBEDE) }; this->headerExtension->id = uint16_t{ htons(0xBEDE) };
this->headerExtension->length = 0u; this->headerExtension->length = 0u;
...@@ -319,6 +321,8 @@ namespace RTC ...@@ -319,6 +321,8 @@ namespace RTC
return false; return false;
} }
MS_ERROR("---------- YES 2 !!!");
// Set the header extension bit. // Set the header extension bit.
this->header->extension = 1u; this->header->extension = 1u;
...@@ -332,7 +336,7 @@ namespace RTC ...@@ -332,7 +336,7 @@ namespace RTC
// Increase size. // Increase size.
this->size += 4; this->size += 4;
// Set the header extension id and length. // Set the header extension id with length 0.
this->headerExtension->id = uint16_t{ htons(0b0001000000000000) }; this->headerExtension->id = uint16_t{ htons(0b0001000000000000) };
this->headerExtension->length = 0u; this->headerExtension->length = 0u;
...@@ -435,27 +439,42 @@ namespace RTC ...@@ -435,27 +439,42 @@ namespace RTC
// Copy payload. // Copy payload.
uint8_t* newPayload{ nullptr }; // Set the payload pointer.
uint8_t* newPayload{ ptr };
if (this->payload != nullptr) if (this->payloadLength != 0)
{ {
numBytes = GetPayloadLength(); numBytes = this->payloadLength;
std::memcpy(ptr, this->payload, numBytes); std::memcpy(ptr, this->payload, numBytes);
// Set the payload pointer.
newPayload = ptr;
// Update pointer. // Update pointer.
ptr += numBytes; ptr += numBytes;
} }
else
{
MS_ERROR("----- OH!! hay this->payload");
}
// Copy payload padding. // Copy payload padding.
if (this->payloadPadding != 0u) if (this->payloadPadding != 0u)
{ {
MS_ERROR("----- OH!! this->payloadPadding:%" PRIu8, this->payloadPadding);
*(ptr + static_cast<size_t>(this->payloadPadding) - 1) = this->payloadPadding; *(ptr + static_cast<size_t>(this->payloadPadding) - 1) = this->payloadPadding;
ptr += size_t{ this->payloadPadding }; ptr += size_t{ this->payloadPadding };
} }
else
{
MS_ERROR("----- OH!! this->payloadPadding == 0");
}
if (static_cast<size_t>(ptr - buffer) != this->size)
{
MS_ERROR(
"----- OH!! (ptr - buffer):%zu, this->size:%zu, this->headerExtension->length:%" PRIu16 ", GetHeaderExtensionLength():%zu",
static_cast<size_t>(ptr - buffer), this->size, this->headerExtension->length, GetHeaderExtensionLength());
}
MS_ASSERT(static_cast<size_t>(ptr - buffer) == this->size, "ptr - buffer == this->size"); MS_ASSERT(static_cast<size_t>(ptr - buffer) == this->size, "ptr - buffer == this->size");
......
...@@ -10,6 +10,7 @@ using namespace RTC; ...@@ -10,6 +10,7 @@ using namespace RTC;
static uint8_t buffer[65536]; static uint8_t buffer[65536];
static uint8_t buffer2[65536]; static uint8_t buffer2[65536];
static uint8_t buffer3[65536];
SCENARIO("parse RTP packets", "[parser][rtp]") SCENARIO("parse RTP packets", "[parser][rtp]")
{ {
...@@ -540,7 +541,10 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -540,7 +541,10 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(clonedPacket->GetPayload()[0] == 0x11); REQUIRE(clonedPacket->GetPayload()[0] == 0x11);
REQUIRE(clonedPacket->GetPayload()[clonedPacket->GetPayloadLength() - 1] == 0xCC); REQUIRE(clonedPacket->GetPayload()[clonedPacket->GetPayloadLength() - 1] == 0xCC);
auto* clonedPacket2 = packet->Clone(buffer3);
delete clonedPacket; delete clonedPacket;
delete clonedPacket2;
} }
SECTION("add Two-Bytes header extensions") SECTION("add Two-Bytes header extensions")
...@@ -600,6 +604,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -600,6 +604,9 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(clonedPacket->GetPayload()[0] == 0x11); REQUIRE(clonedPacket->GetPayload()[0] == 0x11);
REQUIRE(clonedPacket->GetPayload()[clonedPacket->GetPayloadLength() - 1] == 0xCC); REQUIRE(clonedPacket->GetPayload()[clonedPacket->GetPayloadLength() - 1] == 0xCC);
auto* clonedPacket2 = packet->Clone(buffer3);
delete clonedPacket; delete clonedPacket;
delete clonedPacket2;
} }
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论