Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRtpStreamSend: ASAN, fix buffer overflow #1419

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions worker/test/src/RTC/TestRtpStreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

using namespace RTC;

static RtpPacket* CreateRtpPacket(uint8_t* buffer, uint16_t seq, uint32_t timestamp)
static RtpPacket* CreateRtpPacket(uint8_t* buffer, size_t len, uint16_t seq, uint32_t timestamp)
{
auto* packet = RtpPacket::Parse(buffer, 1500);
auto* packet = RtpPacket::Parse(buffer, len);

packet->SetSequenceNumber(seq);
packet->SetTimestamp(timestamp);
Expand Down Expand Up @@ -78,15 +78,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
SECTION("receive NACK and get retransmitted packets")
{
// packet1 [pt:123, seq:21006, timestamp:1533790901]
auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, 1533790901);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901);
// packet2 [pt:123, seq:21007, timestamp:1533790901]
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, 1533790901);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901);
// packet3 [pt:123, seq:21008, timestamp:1533793871]
auto* packet3 = CreateRtpPacket(rtpBuffer3, 21008, 1533793871);
auto* packet3 = CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871);
// packet4 [pt:123, seq:21009, timestamp:1533793871]
auto* packet4 = CreateRtpPacket(rtpBuffer4, 21009, 1533793871);
auto* packet4 = CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871);
// packet5 [pt:123, seq:21010, timestamp:1533796931]
auto* packet5 = CreateRtpPacket(rtpBuffer5, 21010, 1533796931);
auto* packet5 = CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down Expand Up @@ -143,15 +143,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
SECTION("receive NACK and get zero retransmitted packets if useNack is not set")
{
// packet1 [pt:123, seq:21006, timestamp:1533790901]
auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, 1533790901);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901);
// packet2 [pt:123, seq:21007, timestamp:1533790901]
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, 1533790901);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901);
// packet3 [pt:123, seq:21008, timestamp:1533793871]
auto* packet3 = CreateRtpPacket(rtpBuffer3, 21008, 1533793871);
auto* packet3 = CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871);
// packet4 [pt:123, seq:21009, timestamp:1533793871]
auto* packet4 = CreateRtpPacket(rtpBuffer4, 21009, 1533793871);
auto* packet4 = CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871);
// packet5 [pt:123, seq:21010, timestamp:1533796931]
auto* packet5 = CreateRtpPacket(rtpBuffer5, 21010, 1533796931);
auto* packet5 = CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down Expand Up @@ -196,15 +196,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
SECTION("receive NACK and get zero retransmitted packets for audio")
{
// packet1 [pt:123, seq:21006, timestamp:1533790901]
auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, 1533790901);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901);
// packet2 [pt:123, seq:21007, timestamp:1533790901]
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, 1533790901);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901);
// packet3 [pt:123, seq:21008, timestamp:1533793871]
auto* packet3 = CreateRtpPacket(rtpBuffer3, 21008, 1533793871);
auto* packet3 = CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871);
// packet4 [pt:123, seq:21009, timestamp:1533793871]
auto* packet4 = CreateRtpPacket(rtpBuffer4, 21009, 1533793871);
auto* packet4 = CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871);
// packet5 [pt:123, seq:21010, timestamp:1533796931]
auto* packet5 = CreateRtpPacket(rtpBuffer5, 21010, 1533796931);
auto* packet5 = CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down Expand Up @@ -249,9 +249,9 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
SECTION("receive NACK in different RtpStreamSend instances and get retransmitted packets")
{
// packet1 [pt:123, seq:21006, timestamp:1533790901]
auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, 1533790901);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901);
// packet2 [pt:123, seq:21007, timestamp:1533790901]
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, 1533790901);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901);

// Create two RtpStreamSend instances.
TestRtpStreamListener testRtpStreamListener1;
Expand Down Expand Up @@ -326,8 +326,8 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
uint32_t diffTs = RtpStreamSend::MaxRetransmissionDelayForVideoMs * clockRate / 1000;
uint32_t secondTs = firstTs + diffTs;

auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, firstTs);
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, secondTs - 1);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs - 1);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down Expand Up @@ -381,9 +381,9 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
// Send a third packet so it will clean old packets from the buffer.
uint32_t thirdTs = firstTs + (2 * diffTs);

auto* packet1 = CreateRtpPacket(rtpBuffer1, 21006, firstTs);
auto* packet2 = CreateRtpPacket(rtpBuffer2, 21007, secondTs);
auto* packet3 = CreateRtpPacket(rtpBuffer3, 21008, thirdTs);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs);
auto* packet3 = CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, thirdTs);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down Expand Up @@ -430,14 +430,14 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
{
// This scenario reproduce the "too bad sequence number" and "bad sequence
// number" scenarios in RtpStream::UpdateSeq().
auto* packet1 = CreateRtpPacket(rtpBuffer1, 50001, 1000001);
auto* packet2 = CreateRtpPacket(rtpBuffer2, 50002, 1000002);
auto* packet1 = CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 50001, 1000001);
auto* packet2 = CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 50002, 1000002);
// Third packet has bad sequence number (its seq is more than MaxDropout=3000
// older than current max seq) and will be dropped.
auto* packet3 = CreateRtpPacket(rtpBuffer3, 40003, 1000003);
auto* packet3 = CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 40003, 1000003);
// Forth packet has seq=badSeq+1 so will be accepted and will trigger a
// stream reset.
auto* packet4 = CreateRtpPacket(rtpBuffer4, 40004, 1000004);
auto* packet4 = CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 40004, 1000004);

// Create a RtpStreamSend instance.
TestRtpStreamListener testRtpStreamListener;
Expand Down
Loading