Potential division by zero in RtpToNtpMs() in rtp_to_ntp.cc.

CalculateFrequency() results in zero frequency (floating point) if the RTP timestamps in the RTCP list are equal.
Added check in UpdateRtcpList to not insert RTCP SR with the same RTP timestamp.

BUG=webrtc:5780

Review URL: https://codereview.webrtc.org/1891703002

Cr-Commit-Position: refs/heads/master@{#12429}
This commit is contained in:
asapersson 2016-04-19 07:04:47 -07:00 committed by Commit bot
parent e1da27e543
commit fdca66910a
2 changed files with 43 additions and 2 deletions

View File

@ -71,8 +71,9 @@ bool UpdateRtcpList(uint32_t ntp_secs,
for (RtcpList::iterator it = rtcp_list->begin();
it != rtcp_list->end(); ++it) {
if (measurement.ntp_secs == (*it).ntp_secs &&
measurement.ntp_frac == (*it).ntp_frac) {
if ((measurement.ntp_secs == (*it).ntp_secs &&
measurement.ntp_frac == (*it).ntp_frac) ||
(measurement.rtp_timestamp == (*it).rtp_timestamp)) {
// This RTCP has already been added to the list.
return true;
}

View File

@ -135,4 +135,44 @@ TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) {
int64_t timestamp_in_ms = -1;
EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, &timestamp_in_ms));
}
TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualNtp) {
RtcpList rtcp;
uint32_t ntp_sec = 0;
uint32_t ntp_frac = 2;
uint32_t timestamp = 0x12345678;
bool new_sr;
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
EXPECT_TRUE(new_sr);
++timestamp;
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
EXPECT_FALSE(new_sr);
}
TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualTimestamp) {
RtcpList rtcp;
uint32_t ntp_sec = 0;
uint32_t ntp_frac = 2;
uint32_t timestamp = 0x12345678;
bool new_sr;
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
EXPECT_TRUE(new_sr);
++ntp_frac;
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
EXPECT_FALSE(new_sr);
}
TEST(UpdateRtcpListTests, InjectRtcpSrWithZeroNtpFails) {
RtcpList rtcp;
uint32_t ntp_sec = 0;
uint32_t ntp_frac = 0;
uint32_t timestamp = 0x12345678;
bool new_sr;
EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
}
}; // namespace webrtc