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

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

Issue 1219703002: Prevent out-of-bounds reads for short FEC packets. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 5 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 10
11 #include <string.h> 11 #include <string.h>
12 12
13 #include <list> 13 #include <list>
14 14
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/modules/rtp_rtcp/interface/fec_receiver.h" 18 #include "webrtc/modules/rtp_rtcp/interface/fec_receiver.h"
19 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
19 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" 20 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
20 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" 21 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h"
21 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 22 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
22 23
23 using ::testing::_; 24 using ::testing::_;
24 using ::testing::Args; 25 using ::testing::Args;
25 using ::testing::ElementsAreArray; 26 using ::testing::ElementsAreArray;
26 using ::testing::Return; 27 using ::testing::Return;
27 28
28 namespace webrtc { 29 namespace webrtc {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 75 }
75 76
76 void BuildAndAddRedFecPacket(Packet* packet) { 77 void BuildAndAddRedFecPacket(Packet* packet) {
77 RtpPacket* red_packet = generator_->BuildFecRedPacket(packet); 78 RtpPacket* red_packet = generator_->BuildFecRedPacket(packet);
78 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket( 79 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket(
79 red_packet->header.header, red_packet->data, 80 red_packet->header.header, red_packet->data,
80 red_packet->length, kFecPayloadType)); 81 red_packet->length, kFecPayloadType));
81 delete red_packet; 82 delete red_packet;
82 } 83 }
83 84
85 static void SurvivesMaliciousPacket(const uint8_t* data,
86 size_t length,
87 uint8_t ulpfec_payload_type);
88
84 MockRtpData rtp_data_callback_; 89 MockRtpData rtp_data_callback_;
85 rtc::scoped_ptr<ForwardErrorCorrection> fec_; 90 rtc::scoped_ptr<ForwardErrorCorrection> fec_;
86 rtc::scoped_ptr<FecReceiver> receiver_fec_; 91 rtc::scoped_ptr<FecReceiver> receiver_fec_;
87 rtc::scoped_ptr<FrameGenerator> generator_; 92 rtc::scoped_ptr<FrameGenerator> generator_;
88 }; 93 };
89 94
90 void DeletePackets(std::list<Packet*>* packets) { 95 void DeletePackets(std::list<Packet*>* packets) {
91 while (!packets->empty()) { 96 while (!packets->empty()) {
92 delete packets->front(); 97 delete packets->front();
93 packets->pop_front(); 98 packets->pop_front();
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // and should've been dropped. Only the media packet we inserted will be 360 // and should've been dropped. Only the media packet we inserted will be
356 // returned. 361 // returned.
357 BuildAndAddRedMediaPacket(media_rtp_packets.front()); 362 BuildAndAddRedMediaPacket(media_rtp_packets.front());
358 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) 363 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _))
359 .Times(1).WillRepeatedly(Return(true)); 364 .Times(1).WillRepeatedly(Return(true));
360 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); 365 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec());
361 366
362 DeletePackets(&media_packets); 367 DeletePackets(&media_packets);
363 } 368 }
364 369
370 void ReceiverFecTest::SurvivesMaliciousPacket(const uint8_t* data,
371 size_t length,
372 uint8_t ulpfec_payload_type) {
373 webrtc::RTPHeader header;
374 rtc::scoped_ptr<webrtc::RtpHeaderParser> parser(
375 webrtc::RtpHeaderParser::Create());
376 ASSERT_TRUE(parser->Parse(data, length, &header));
377
378 webrtc::NullRtpData null_callback;
379 rtc::scoped_ptr<webrtc::FecReceiver> receiver_fec(
380 webrtc::FecReceiver::Create(&null_callback));
381
382 receiver_fec->AddReceivedRedPacket(header, data, length, ulpfec_payload_type);
383 }
384
385 TEST_F(ReceiverFecTest, TruncatedPacketWithFBitSet) {
386 const uint8_t kTruncatedPacket[] = {0x80,
387 0x2a,
388 0x68,
389 0x71,
390 0x29,
391 0xa1,
392 0x27,
393 0x3a,
394 0x29,
395 0x12,
396 0x2a,
397 0x98,
398 0xe0,
399 0x29};
400
401 SurvivesMaliciousPacket(kTruncatedPacket, sizeof(kTruncatedPacket), 100);
402 }
403
365 } // namespace webrtc 404 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698