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

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

Issue 1226203002: Avoid overflow in checking for emulation bytes in rbsp. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added clarifying comment 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 | 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) 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 + 3 < byte_length_ && sps_[i] == 0 && sps_[i + 1] == 0 && 39 // Be careful about over/underflow here. byte_length_ - 3 can underflow, and
40 // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_
41 // above, and that expression will produce the number of bytes left in
42 // the stream including the byte at i.
43 if (byte_length_ - i >= 3 && sps_[i] == 0 && sps_[i + 1] == 0 &&
40 sps_[i + 2] == 3) { 44 sps_[i + 2] == 3) {
41 // Two rbsp bytes + the emulation byte. 45 // Two rbsp bytes + the emulation byte.
42 rbsp_buffer.WriteBytes(sps_bytes + i, 2); 46 rbsp_buffer.WriteBytes(sps_bytes + i, 2);
43 i += 3; 47 i += 3;
44 } else { 48 } else {
45 // Single rbsp byte. 49 // Single rbsp byte.
46 rbsp_buffer.WriteBytes(sps_bytes + i, 1); 50 rbsp_buffer.WriteBytes(sps_bytes + i, 1);
47 i++; 51 i++;
48 } 52 }
49 } 53 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Subtract the crop for each dimension. 223 // Subtract the crop for each dimension.
220 width -= (frame_crop_left_offset + frame_crop_right_offset); 224 width -= (frame_crop_left_offset + frame_crop_right_offset);
221 height -= (frame_crop_top_offset + frame_crop_bottom_offset); 225 height -= (frame_crop_top_offset + frame_crop_bottom_offset);
222 226
223 width_ = width; 227 width_ = width;
224 height_ = height; 228 height_ = height;
225 return true; 229 return true;
226 } 230 }
227 231
228 } // namespace webrtc 232 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698