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

Side by Side Diff: webrtc/common_video/h264/h264_bitstream_parser.cc

Issue 2532973002: Sanity check parsed QP values from H264 bitstream (Closed)
Patch Set: Created 4 years 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 #include "webrtc/common_video/h264/h264_bitstream_parser.h" 10 #include "webrtc/common_video/h264/h264_bitstream_parser.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 if (pps_->entropy_coding_mode_flag && 245 if (pps_->entropy_coding_mode_flag &&
246 slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) { 246 slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) {
247 // cabac_init_idc: ue(v) 247 // cabac_init_idc: ue(v)
248 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp)); 248 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp));
249 } 249 }
250 250
251 int32_t last_slice_qp_delta; 251 int32_t last_slice_qp_delta;
252 RETURN_INV_ON_FAIL( 252 RETURN_INV_ON_FAIL(
253 slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta)); 253 slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta));
254 if (last_slice_qp_delta > 52 || last_slice_qp_delta < -52) {
magjed_webrtc 2016/11/28 16:41:32 Is the constant 52 specified by the spec? We shoul
pbos-webrtc 2016/11/28 17:15:45 I think you should also add range checking in GetL
kthelgason 2016/11/29 10:27:12 Yes, and done.
kthelgason 2016/11/29 10:27:12 Yes, and done.
255 // Something has gone wrong, and the parsed value is invalid.
256 LOG(LS_WARNING) << "Parsed QP value out of range.";
257 return kInvalidStream;
258 }
259
254 last_slice_qp_delta_ = rtc::Optional<int32_t>(last_slice_qp_delta); 260 last_slice_qp_delta_ = rtc::Optional<int32_t>(last_slice_qp_delta);
255 return kOk; 261 return kOk;
256 } 262 }
257 263
258 void H264BitstreamParser::ParseSlice(const uint8_t* slice, size_t length) { 264 void H264BitstreamParser::ParseSlice(const uint8_t* slice, size_t length) {
259 H264::NaluType nalu_type = H264::ParseNaluType(slice[0]); 265 H264::NaluType nalu_type = H264::ParseNaluType(slice[0]);
260 switch (nalu_type) { 266 switch (nalu_type) {
261 case H264::NaluType::kSps: { 267 case H264::NaluType::kSps: {
262 sps_ = SpsParser::ParseSps(slice + H264::kNaluTypeSize, 268 sps_ = SpsParser::ParseSps(slice + H264::kNaluTypeSize,
263 length - H264::kNaluTypeSize); 269 length - H264::kNaluTypeSize);
(...skipping 25 matching lines...) Expand all
289 } 295 }
290 296
291 bool H264BitstreamParser::GetLastSliceQp(int* qp) const { 297 bool H264BitstreamParser::GetLastSliceQp(int* qp) const {
292 if (!last_slice_qp_delta_ || !pps_) 298 if (!last_slice_qp_delta_ || !pps_)
293 return false; 299 return false;
294 *qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_; 300 *qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_;
295 return true; 301 return true;
296 } 302 }
297 303
298 } // namespace webrtc 304 } // 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