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

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

Issue 2532973002: Sanity check parsed QP values from H264 bitstream (Closed)
Patch Set: Add check to PPS parser as well 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 "webrtc/common_video/h264/pps_parser.h" 11 #include "webrtc/common_video/h264/pps_parser.h"
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/common_video/h264/h264_common.h" 15 #include "webrtc/common_video/h264/h264_common.h"
16 #include "webrtc/base/bitbuffer.h" 16 #include "webrtc/base/bitbuffer.h"
17 #include "webrtc/base/buffer.h" 17 #include "webrtc/base/buffer.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 19
20 #define RETURN_EMPTY_ON_FAIL(x) \ 20 #define RETURN_EMPTY_ON_FAIL(x) \
21 if (!(x)) { \ 21 if (!(x)) { \
22 return rtc::Optional<PpsParser::PpsState>(); \ 22 return rtc::Optional<PpsParser::PpsState>(); \
23 } 23 }
24 24
25 namespace {
26 int kMaxAbsPicInitQpDeltaValue = 25;
magjed_webrtc 2016/11/29 10:34:32 nit: const
27 }
28
25 namespace webrtc { 29 namespace webrtc {
26 30
27 // General note: this is based off the 02/2014 version of the H.264 standard. 31 // General note: this is based off the 02/2014 version of the H.264 standard.
28 // You can find it on this page: 32 // You can find it on this page:
29 // http://www.itu.int/rec/T-REC-H.264 33 // http://www.itu.int/rec/T-REC-H.264
30 34
31 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data, 35 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data,
32 size_t length) { 36 size_t length) {
33 // First, parse out rbsp, which is basically the source buffer minus emulation 37 // First, parse out rbsp, which is basically the source buffer minus emulation
34 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in 38 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // weighted_pred_flag: u(1) 159 // weighted_pred_flag: u(1)
156 uint32_t weighted_pred_flag; 160 uint32_t weighted_pred_flag;
157 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&weighted_pred_flag, 1)); 161 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&weighted_pred_flag, 1));
158 pps.weighted_pred_flag = weighted_pred_flag != 0; 162 pps.weighted_pred_flag = weighted_pred_flag != 0;
159 // weighted_bipred_idc: u(2) 163 // weighted_bipred_idc: u(2)
160 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&pps.weighted_bipred_idc, 2)); 164 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&pps.weighted_bipred_idc, 2));
161 165
162 // pic_init_qp_minus26: se(v) 166 // pic_init_qp_minus26: se(v)
163 RETURN_EMPTY_ON_FAIL( 167 RETURN_EMPTY_ON_FAIL(
164 bit_buffer->ReadSignedExponentialGolomb(&pps.pic_init_qp_minus26)); 168 bit_buffer->ReadSignedExponentialGolomb(&pps.pic_init_qp_minus26));
169 // Sanity-check parsed value
170 if (abs(pps.pic_init_qp_minus26) > kMaxAbsPicInitQpDeltaValue) {
171 RETURN_EMPTY_ON_FAIL(false);
172 }
165 // pic_init_qs_minus26: se(v) 173 // pic_init_qs_minus26: se(v)
166 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored)); 174 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
167 // chroma_qp_index_offset: se(v) 175 // chroma_qp_index_offset: se(v)
168 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored)); 176 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
169 // deblocking_filter_control_present_flag: u(1) 177 // deblocking_filter_control_present_flag: u(1)
170 // constrained_intra_pred_flag: u(1) 178 // constrained_intra_pred_flag: u(1)
171 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2)); 179 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2));
172 // redundant_pic_cnt_present_flag: u(1) 180 // redundant_pic_cnt_present_flag: u(1)
173 RETURN_EMPTY_ON_FAIL( 181 RETURN_EMPTY_ON_FAIL(
174 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1)); 182 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1));
175 183
176 return rtc::Optional<PpsParser::PpsState>(pps); 184 return rtc::Optional<PpsParser::PpsState>(pps);
177 } 185 }
178 186
179 bool PpsParser::ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer, 187 bool PpsParser::ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer,
180 uint32_t* pps_id, 188 uint32_t* pps_id,
181 uint32_t* sps_id) { 189 uint32_t* sps_id) {
182 // pic_parameter_set_id: ue(v) 190 // pic_parameter_set_id: ue(v)
183 if (!bit_buffer->ReadExponentialGolomb(pps_id)) 191 if (!bit_buffer->ReadExponentialGolomb(pps_id))
184 return false; 192 return false;
185 // seq_parameter_set_id: ue(v) 193 // seq_parameter_set_id: ue(v)
186 if (!bit_buffer->ReadExponentialGolomb(sps_id)) 194 if (!bit_buffer->ReadExponentialGolomb(sps_id))
187 return false; 195 return false;
188 return true; 196 return true;
189 } 197 }
190 198
191 } // namespace webrtc 199 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698