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

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

Issue 1218013002: Prevent OOB reads for zero-length H264 payloads. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 "webrtc/base/logging.h"
13 #include "webrtc/modules/interface/module_common_types.h" 14 #include "webrtc/modules/interface/module_common_types.h"
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
15 #include "webrtc/modules/rtp_rtcp/source/h264_sps_parser.h" 16 #include "webrtc/modules/rtp_rtcp/source/h264_sps_parser.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h" 17 #include "webrtc/modules/rtp_rtcp/source/rtp_format_h264.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 namespace { 20 namespace {
20 21
21 enum Nalu { 22 enum Nalu {
22 kSlice = 1, 23 kSlice = 1,
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 310 }
310 311
311 std::string RtpPacketizerH264::ToString() { 312 std::string RtpPacketizerH264::ToString() {
312 return "RtpPacketizerH264"; 313 return "RtpPacketizerH264";
313 } 314 }
314 315
315 bool RtpDepacketizerH264::Parse(ParsedPayload* parsed_payload, 316 bool RtpDepacketizerH264::Parse(ParsedPayload* parsed_payload,
316 const uint8_t* payload_data, 317 const uint8_t* payload_data,
317 size_t payload_data_length) { 318 size_t payload_data_length) {
318 assert(parsed_payload != NULL); 319 assert(parsed_payload != NULL);
320 if (payload_data_length == 0) {
321 LOG(LS_ERROR) << "Empty payload.";
322 return false;
323 }
324
319 uint8_t nal_type = payload_data[0] & kTypeMask; 325 uint8_t nal_type = payload_data[0] & kTypeMask;
320 size_t offset = 0; 326 size_t offset = 0;
321 if (nal_type == kFuA) { 327 if (nal_type == kFuA) {
322 // Fragmented NAL units (FU-A). 328 // Fragmented NAL units (FU-A).
323 ParseFuaNalu(parsed_payload, payload_data, payload_data_length, &offset); 329 ParseFuaNalu(parsed_payload, payload_data, payload_data_length, &offset);
324 } else { 330 } else {
325 // We handle STAP-A and single NALU's the same way here. The jitter buffer 331 // We handle STAP-A and single NALU's the same way here. The jitter buffer
326 // will depacketize the STAP-A into NAL units later. 332 // will depacketize the STAP-A into NAL units later.
327 ParseSingleNalu(parsed_payload, payload_data, payload_data_length); 333 ParseSingleNalu(parsed_payload, payload_data, payload_data_length);
328 } 334 }
329 335
330 parsed_payload->payload = payload_data + offset; 336 parsed_payload->payload = payload_data + offset;
331 parsed_payload->payload_length = payload_data_length - offset; 337 parsed_payload->payload_length = payload_data_length - offset;
332 return true; 338 return true;
333 } 339 }
334 } // namespace webrtc 340 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698