History

avcodec/mpeg12dec: use init_get_bits8 and check the return value in all remaining cases

James Almer committed 3 years ago

Commit 4a80db51 parent efbe84e1 file · +22 −7Browse files

Unified · Split

libavcodec/mpeg12dec.c+22−7
@@ -1694,7 +1694,10 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, · 1693 unmodified lines
16941694
16951695 av_assert0(mb_y < s->mb_height);
16961696
1697− init_get_bits(&s->gb, *buf, buf_size * 8);
1697+ ret = init_get_bits8(&s->gb, *buf, buf_size);
1698+ if (ret < 0)
1699+ return ret;
1700+
16981701 if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
16991702 skip_bits(&s->gb, 3);
17001703
@@ -2063,7 +2066,9 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, · 362 unmodified lines
20632066 int width, height;
20642067 int i, v, j;
20652068
2066− init_get_bits(&s->gb, buf, buf_size * 8);
2069+ int ret = init_get_bits8(&s->gb, buf, buf_size);
2070+ if (ret < 0)
2071+ return ret;
20672072
20682073 width = get_bits(&s->gb, 12);
20692074 height = get_bits(&s->gb, 12);
@@ -2228,7 +2233,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, · 158 unmodified lines
22282233 int cc_count = 0;
22292234 int i, ret;
22302235
2231− init_get_bits8(&gb, p + 2, buf_size - 2);
2236+ ret = init_get_bits8(&gb, p + 2, buf_size - 2);
2237+ if (ret < 0)
2238+ return ret;
22322239 cc_count = get_bits(&gb, 5);
22332240 if (cc_count > 0) {
22342241 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
@@ -2400,7 +2407,7 @@ static void mpeg_decode_user_data(AVCodecContext *avctx, · 165 unmodified lines
24002407 }
24012408 }
24022409
2403−static void mpeg_decode_gop(AVCodecContext *avctx,
2410+static int mpeg_decode_gop(AVCodecContext *avctx,
24042411 const uint8_t *buf, int buf_size)
24052412 {
24062413 Mpeg1Context *s1 = avctx->priv_data;
@@ -2408,7 +2415,9 @@ static void mpeg_decode_gop(AVCodecContext *avctx, · 1 unmodified line
24082415 int broken_link;
24092416 int64_t tc;
24102417
2411− init_get_bits(&s->gb, buf, buf_size * 8);
2418+ int ret = init_get_bits8(&s->gb, buf, buf_size);
2419+ if (ret < 0)
2420+ return ret;
24122421
24132422 tc = s1->timecode_frame_start = get_bits(&s->gb, 25);
24142423
@@ -2425,6 +2434,8 @@ static void mpeg_decode_gop(AVCodecContext *avctx, · 10 unmodified lines
24252434 "GOP (%s) closed_gop=%d broken_link=%d\n",
24262435 tcbuf, s1->closed_gop, broken_link);
24272436 }
2437+
2438+ return 0;
24282439 }
24292440
24302441 static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
@@ -2594,7 +2605,9 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 163 unmodified lines
25942605 case GOP_START_CODE:
25952606 if (last_code == 0) {
25962607 s2->first_field = 0;
2597− mpeg_decode_gop(avctx, buf_ptr, input_size);
2608+ ret = mpeg_decode_gop(avctx, buf_ptr, input_size);
2609+ if (ret < 0)
2610+ return ret;
25982611 s->sync = 1;
25992612 } else {
26002613 av_log(avctx, AV_LOG_ERROR,
@@ -2734,7 +2747,9 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 133 unmodified lines
27342747 if (ret < 0)
27352748 return ret;
27362749 }
2737− init_get_bits(&thread_context->gb, buf_ptr, input_size * 8);
2750+ ret = init_get_bits8(&thread_context->gb, buf_ptr, input_size);
2751+ if (ret < 0)
2752+ return ret;
27382753 s->slice_count++;
27392754 }
27402755 buf_ptr += 2; // FIXME add minimum number of bytes per slice

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