Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc

Issue 2327743003: Fix oversized rtp header extension parsing. (Closed)
Patch Set: Fix + nits nearby Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" 10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 // Extension should be ignored. 217 // Extension should be ignored.
218 int32_t time_offset; 218 int32_t time_offset;
219 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); 219 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
220 220
221 // But shouldn't prevent reading payload. 221 // But shouldn't prevent reading payload.
222 EXPECT_THAT(make_tuple(packet.payload(), packet.payload_size()), 222 EXPECT_THAT(make_tuple(packet.payload(), packet.payload_size()),
223 ElementsAreArray(kPayload)); 223 ElementsAreArray(kPayload));
224 } 224 }
225 225
226 TEST(RtpPacketTest, ParseWithOverSizedExtension) {
227 // clang-format off
228 const uint8_t bad_packet[] = {
229 0x90, kPayloadType, 0x00, kSeqNum,
230 0x65, 0x43, 0x12, 0x78, // kTimestamp.
231 0x12, 0x34, 0x56, 0x78, // kSsrc.
232 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word.
233 0x00, // Add a byte of padding.
234 0x12, // Extension id 1 size (2+1).
235 0xda, 0x1a // Only 2 bytes of extension payload.
236 };
237 // clang-format on
238 RtpPacketToSend::ExtensionManager extensions;
239 extensions.Register(TransmissionOffset::kId, 1);
240 RtpPacketReceived packet(&extensions);
241
242 // Parse should ignore bad extension and proceed.
243 EXPECT_TRUE(packet.Parse(bad_packet, sizeof(bad_packet)));
244 int32_t time_offset;
245 // But extracting extension should fail.
246 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
247 }
248
226 TEST(RtpPacketTest, ParseWith2Extensions) { 249 TEST(RtpPacketTest, ParseWith2Extensions) {
227 RtpPacketToSend::ExtensionManager extensions; 250 RtpPacketToSend::ExtensionManager extensions;
228 extensions.Register(kRtpExtensionTransmissionTimeOffset, 251 extensions.Register(kRtpExtensionTransmissionTimeOffset,
229 kTransmissionOffsetExtensionId); 252 kTransmissionOffsetExtensionId);
230 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId); 253 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId);
231 RtpPacketReceived packet(&extensions); 254 RtpPacketReceived packet(&extensions);
232 EXPECT_TRUE(packet.Parse(kPacketWithTOAndAL, sizeof(kPacketWithTOAndAL))); 255 EXPECT_TRUE(packet.Parse(kPacketWithTOAndAL, sizeof(kPacketWithTOAndAL)));
233 int32_t time_offset; 256 int32_t time_offset;
234 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); 257 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset));
235 EXPECT_EQ(kTimeOffset, time_offset); 258 EXPECT_EQ(kTimeOffset, time_offset);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 int32_t time_offset; 296 int32_t time_offset;
274 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); 297 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
275 packet.IdentifyExtensions(&extensions); 298 packet.IdentifyExtensions(&extensions);
276 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); 299 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset));
277 EXPECT_EQ(kTimeOffset, time_offset); 300 EXPECT_EQ(kTimeOffset, time_offset);
278 EXPECT_EQ(0u, packet.payload_size()); 301 EXPECT_EQ(0u, packet.payload_size());
279 EXPECT_EQ(0u, packet.padding_size()); 302 EXPECT_EQ(0u, packet.padding_size());
280 } 303 }
281 304
282 } // namespace webrtc 305 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698