From a17651f7d8748905d902eedf34471a0c227ca789 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Wed, 6 Jul 2022 16:24:41 +0200 Subject: [PATCH] Fix overflow due to rounding in AbsoluteSendTime::To24Bits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Actual rounding is not important for this time as long it is consistent during the call: only difference between two absolute send time matter Rounding down avoids producing 1 < 24 when value is close to the wrap around boundary. Bug: None Change-Id: Ibbf5bae21bc37eccdc5d4c130a59796ee5108017 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/268001 Commit-Queue: Åsa Persson Auto-Submit: Danil Chapovalov Reviewed-by: Åsa Persson Cr-Commit-Position: refs/heads/main@{#37468} --- modules/rtp_rtcp/source/rtp_header_extensions.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/rtp_rtcp/source/rtp_header_extensions.h b/modules/rtp_rtcp/source/rtp_header_extensions.h index 62b19293ba..d80e0da4f8 100644 --- a/modules/rtp_rtcp/source/rtp_header_extensions.h +++ b/modules/rtp_rtcp/source/rtp_header_extensions.h @@ -26,7 +26,6 @@ #include "api/video/video_rotation.h" #include "api/video/video_timing.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "rtc_base/numerics/divide_round.h" namespace webrtc { @@ -45,7 +44,7 @@ class AbsoluteSendTime { static constexpr uint32_t To24Bits(Timestamp time) { int64_t time_us = time.us() % (int64_t{1 << 6} * 1'000'000); - int64_t time6x18 = DivideRoundToNearest(time_us << 18, 1'000'000); + int64_t time6x18 = (time_us << 18) / 1'000'000; RTC_DCHECK_GE(time6x18, 0); RTC_DCHECK_LT(time6x18, 1 << 24); return static_cast(time6x18);