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

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

Issue 1219493004: Prevent size_t underflow in H264 SPS parsing. (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
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc » ('j') | 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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
(...skipping 18 matching lines...) Expand all
29 // General note: this is based off the 02/2014 version of the H.264 standard. 29 // General note: this is based off the 02/2014 version of the H.264 standard.
30 // You can find it on this page: 30 // You can find it on this page:
31 // http://www.itu.int/rec/T-REC-H.264 31 // http://www.itu.int/rec/T-REC-H.264
32 32
33 const char* sps_bytes = reinterpret_cast<const char*>(sps_); 33 const char* sps_bytes = reinterpret_cast<const char*>(sps_);
34 // First, parse out rbsp, which is basically the source buffer minus emulation 34 // First, parse out rbsp, which is basically the source buffer minus emulation
35 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in 35 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
36 // section 7.3.1 of the H.264 standard. 36 // section 7.3.1 of the H.264 standard.
37 rtc::ByteBuffer rbsp_buffer; 37 rtc::ByteBuffer rbsp_buffer;
38 for (size_t i = 0; i < byte_length_;) { 38 for (size_t i = 0; i < byte_length_;) {
39 if (i < byte_length_ - 3 && 39 if (i + 3 < byte_length_ && sps_[i] == 0 && sps_[i + 1] == 0 &&
stefan-webrtc 2015/07/01 09:59:13 Interesting bug. :)
noahric 2015/07/01 16:34:38 I think this introduced a separate bug, though you
pbos-webrtc 2015/07/01 18:12:29 So just to clarify: The bug I fixed gets hit from
noahric 2015/07/01 18:49:24 I think the most readable fix is: if (byte_length
pbos-webrtc 2015/07/02 07:37:50 Slightly less readable in my opinion, but I won't
40 sps_[i] == 0 && sps_[i + 1] == 0 && sps_[i + 2] == 3) { 40 sps_[i + 2] == 3) {
41 // Two rbsp bytes + the emulation byte. 41 // Two rbsp bytes + the emulation byte.
42 rbsp_buffer.WriteBytes(sps_bytes + i, 2); 42 rbsp_buffer.WriteBytes(sps_bytes + i, 2);
43 i += 3; 43 i += 3;
44 } else { 44 } else {
45 // Single rbsp byte. 45 // Single rbsp byte.
46 rbsp_buffer.WriteBytes(sps_bytes + i, 1); 46 rbsp_buffer.WriteBytes(sps_bytes + i, 1);
47 i++; 47 i++;
48 } 48 }
49 } 49 }
50 50
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Subtract the crop for each dimension. 219 // Subtract the crop for each dimension.
220 width -= (frame_crop_left_offset + frame_crop_right_offset); 220 width -= (frame_crop_left_offset + frame_crop_right_offset);
221 height -= (frame_crop_top_offset + frame_crop_bottom_offset); 221 height -= (frame_crop_top_offset + frame_crop_bottom_offset);
222 222
223 width_ = width; 223 width_ = width;
224 height_ = height; 224 height_ = height;
225 return true; 225 return true;
226 } 226 }
227 227
228 } // namespace webrtc 228 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698