From d525f03f8b7c498370e537bce1cbe36b4108bde2 Mon Sep 17 00:00:00 2001 From: Victor Gaydov Date: Thu, 25 Jul 2024 21:17:10 +0400 Subject: [PATCH] bugfix: Fix seqnum overflow handling in rtcp::PacketCounter --- src/internal_modules/roc_rtcp/packet_counter.cpp | 2 +- src/tests/roc_rtcp/test_packet_counter.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal_modules/roc_rtcp/packet_counter.cpp b/src/internal_modules/roc_rtcp/packet_counter.cpp index ebac413e6..49bb3cee2 100644 --- a/src/internal_modules/roc_rtcp/packet_counter.cpp +++ b/src/internal_modules/roc_rtcp/packet_counter.cpp @@ -31,7 +31,7 @@ uint64_t PacketCounter::update(const uint32_t begin, const uint32_t end) { // Update end. if (int32_t(end - end64_lo_) > 0) { if (end < end64_lo_) { - end64_hi_ += (uint32_t)-1; + end64_hi_ += (uint64_t)1 << 32; } end64_lo_ = end; } diff --git a/src/tests/roc_rtcp/test_packet_counter.cpp b/src/tests/roc_rtcp/test_packet_counter.cpp index 8afa29c47..faede3316 100644 --- a/src/tests/roc_rtcp/test_packet_counter.cpp +++ b/src/tests/roc_rtcp/test_packet_counter.cpp @@ -35,10 +35,10 @@ TEST(packet_counter, wrap) { UNSIGNED_LONGS_EQUAL(10, pc.update(0xFFFFFFFF - 30, 0xFFFFFFFF - 20)); UNSIGNED_LONGS_EQUAL(20, pc.update(0xFFFFFFFF - 30, 0xFFFFFFFF - 10)); - UNSIGNED_LONGS_EQUAL(40, pc.update(0xFFFFFFFF - 30, 10)); - UNSIGNED_LONGS_EQUAL(60, pc.update(0xFFFFFFFF - 30, 30)); - UNSIGNED_LONGS_EQUAL(60, pc.update(0xFFFFFFFF - 30, 20)); - UNSIGNED_LONGS_EQUAL(70, pc.update(0xFFFFFFFF - 30, 40)); + UNSIGNED_LONGS_EQUAL(41, pc.update(0xFFFFFFFF - 30, 10)); + UNSIGNED_LONGS_EQUAL(61, pc.update(0xFFFFFFFF - 30, 30)); + UNSIGNED_LONGS_EQUAL(61, pc.update(0xFFFFFFFF - 30, 20)); + UNSIGNED_LONGS_EQUAL(71, pc.update(0xFFFFFFFF - 30, 40)); UNSIGNED_LONGS_EQUAL(10, pc.update(10, 20)); }