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

Side by Side Diff: content/common/gpu/media/h264_decoder.cc

Issue 1896533002: Check frame coded size in H264 parsers to avoid integer overflows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | media/formats/mp2t/es_parser_h264.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <limits> 6 #include <limits>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 DVLOG(1) << "frame_mbs_only_flag != 1 not supported"; 1079 DVLOG(1) << "frame_mbs_only_flag != 1 not supported";
1080 return false; 1080 return false;
1081 } 1081 }
1082 1082
1083 // Calculate picture height/width in macroblocks and pixels 1083 // Calculate picture height/width in macroblocks and pixels
1084 // (spec 7.4.2.1.1, 7.4.3). 1084 // (spec 7.4.2.1.1, 7.4.3).
1085 int width_mb = sps->pic_width_in_mbs_minus1 + 1; 1085 int width_mb = sps->pic_width_in_mbs_minus1 + 1;
1086 int height_mb = (2 - sps->frame_mbs_only_flag) * 1086 int height_mb = (2 - sps->frame_mbs_only_flag) *
1087 (sps->pic_height_in_map_units_minus1 + 1); 1087 (sps->pic_height_in_map_units_minus1 + 1);
1088 1088
1089 if (width_mb > std::numeric_limits<int>::max() / 16 ||
Pawel Osciak 2016/04/20 04:22:09 Could we perhaps use: base::IsValueInRangeForNumer
servolk 2016/04/20 17:32:53 Well, we are actually trying to avoid integer over
Pawel Osciak 2016/04/21 01:03:53 Yes, unless the result was of a larger type: int a
servolk 2016/04/21 01:24:06 First of all, you probably meant 16ull, as 16u is
1090 height_mb > std::numeric_limits<int>::max() / 16) {
1091 DVLOG(1) << "Picture size is too big: width_mb=" << width_mb
1092 << " height_mb=" << height_mb;
1093 return false;
1094 }
1095
1089 gfx::Size new_pic_size(16 * width_mb, 16 * height_mb); 1096 gfx::Size new_pic_size(16 * width_mb, 16 * height_mb);
1090 if (new_pic_size.IsEmpty()) { 1097 if (new_pic_size.IsEmpty()) {
1091 DVLOG(1) << "Invalid picture size: " << new_pic_size.ToString(); 1098 DVLOG(1) << "Invalid picture size: " << new_pic_size.ToString();
1092 return false; 1099 return false;
1093 } 1100 }
1094 1101
1095 if (!pic_size_.IsEmpty() && new_pic_size == pic_size_) { 1102 if (!pic_size_.IsEmpty() && new_pic_size == pic_size_) {
1096 // Already have surfaces and this SPS keeps the same resolution, 1103 // Already have surfaces and this SPS keeps the same resolution,
1097 // no need to request a new set. 1104 // no need to request a new set.
1098 return true; 1105 return true;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 1421
1415 gfx::Size H264Decoder::GetPicSize() const { 1422 gfx::Size H264Decoder::GetPicSize() const {
1416 return pic_size_; 1423 return pic_size_;
1417 } 1424 }
1418 1425
1419 size_t H264Decoder::GetRequiredNumOfPictures() const { 1426 size_t H264Decoder::GetRequiredNumOfPictures() const {
1420 return dpb_.max_num_pics() + kPicsInPipeline; 1427 return dpb_.max_num_pics() + kPicsInPipeline;
1421 } 1428 }
1422 1429
1423 } // namespace content 1430 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/formats/mp2t/es_parser_h264.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698