History

hevc_ps: verify P/T/L information

This makes the SPS parsing a little, but barely, safer.

Christophe Gisquet committed 12 years ago

Commit 0d0d24a1 parent 07262c71 file · +34 −9Browse files

Unified · Split

libavcodec/hevc_ps.c+34−9
@@ -199,12 +199,15 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, · 198 unmodified lines
199199 }
200200
201201
202−static void decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl)
202+static int decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl)
203203 {
204204 int i;
205205 HEVCLocalContext *lc = s->HEVClc;
206206 GetBitContext *gb = &lc->gb;
207207
208+ if (get_bits_left(gb) < 2+1+5 + 32 + 4 + 16 + 16 + 12)
209+ return -1;
210+
208211 ptl->profile_space = get_bits(gb, 2);
209212 ptl->tier_flag = get_bits1(gb);
210213 ptl->profile_idc = get_bits(gb, 5);
@@ -229,29 +232,49 @@ static void decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl) · 18 unmodified lines
229232 skip_bits(gb, 16); // XXX_reserved_zero_44bits[0..15]
230233 skip_bits(gb, 16); // XXX_reserved_zero_44bits[16..31]
231234 skip_bits(gb, 12); // XXX_reserved_zero_44bits[32..43]
235+
236+ return 0;
232237 }
233238
234−static void parse_ptl(HEVCContext *s, PTL *ptl, int max_num_sub_layers)
239+static int parse_ptl(HEVCContext *s, PTL *ptl, int max_num_sub_layers)
235240 {
236241 int i;
237242 HEVCLocalContext *lc = s->HEVClc;
238243 GetBitContext *gb = &lc->gb;
239− decode_profile_tier_level(s, &ptl->general_ptl);
244+ if (decode_profile_tier_level(s, &ptl->general_ptl) < 0 ||
245+ get_bits_left(gb) < 8 + 8*2) {
246+ av_log(s->avctx, AV_LOG_ERROR, "PTL information too short\n");
247+ return -1;
248+ }
249+
240250 ptl->general_ptl.level_idc = get_bits(gb, 8);
241251
242252 for (i = 0; i < max_num_sub_layers - 1; i++) {
243253 ptl->sub_layer_profile_present_flag[i] = get_bits1(gb);
244254 ptl->sub_layer_level_present_flag[i] = get_bits1(gb);
245255 }
256+
246257 if (max_num_sub_layers - 1> 0)
247258 for (i = max_num_sub_layers - 1; i < 8; i++)
248259 skip_bits(gb, 2); // reserved_zero_2bits[i]
249260 for (i = 0; i < max_num_sub_layers - 1; i++) {
250− if (ptl->sub_layer_profile_present_flag[i])
251− decode_profile_tier_level(s, &ptl->sub_layer_ptl[i]);
252− if (ptl->sub_layer_level_present_flag[i])
253− ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8);
261+ if (ptl->sub_layer_profile_present_flag[i] &&
262+ decode_profile_tier_level(s, &ptl->sub_layer_ptl[i]) < 0) {
263+ av_log(s->avctx, AV_LOG_ERROR,
264+ "PTL information for sublayer %i too short\n", i);
265+ return -1;
266+ }
267+ if (ptl->sub_layer_level_present_flag[i]) {
268+ if (get_bits_left(gb) < 8) {
269+ av_log(s->avctx, AV_LOG_ERROR,
270+ "Not enough data for sublayer %i level_idc\n", i);
271+ return -1;
272+ } else
273+ ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8);
274+ }
254275 }
276+
277+ return 0;
255278 }
256279
257280 static void decode_sublayer_hrd(HEVCContext *s, unsigned int nb_cpb,
@@ -375,7 +398,8 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) · 117 unmodified lines
375398 goto err;
376399 }
377400
378− parse_ptl(s, &vps->ptl, vps->vps_max_sub_layers);
401+ if (parse_ptl(s, &vps->ptl, vps->vps_max_sub_layers) < 0)
402+ goto err;
379403
380404 vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb);
381405
@@ -692,7 +716,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) · 310 unmodified lines
692716
693717 skip_bits1(gb); // temporal_id_nesting_flag
694718
695− parse_ptl(s, &sps->ptl, sps->max_sub_layers);
719+ if (parse_ptl(s, &sps->ptl, sps->max_sub_layers) < 0)
720+ goto err;
696721
697722 sps_id = get_ue_golomb_long(gb);
698723 if (sps_id >= MAX_SPS_COUNT) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t