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
1694 1694
1695 av_assert0(mb_y < s->mb_height);1695 av_assert0(mb_y < s->mb_height);
1696 1696
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
1698 if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)1701 if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
1699 skip_bits(&s->gb, 3);1702 skip_bits(&s->gb, 3);
1700 1703
@@ -2063,7 +2066,9 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, · 362 unmodified lines
2063 int width, height;2066 int width, height;
2064 int i, v, j;2067 int i, v, j;
2065 2068
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;
2067 2072
2068 width = get_bits(&s->gb, 12);2073 width = get_bits(&s->gb, 12);
2069 height = get_bits(&s->gb, 12);2074 height = get_bits(&s->gb, 12);
@@ -2228,7 +2233,9 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, · 158 unmodified lines
2228 int cc_count = 0;2233 int cc_count = 0;
2229 int i, ret;2234 int i, ret;
2230 2235
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;
2232 cc_count = get_bits(&gb, 5);2239 cc_count = get_bits(&gb, 5);
2233 if (cc_count > 0) {2240 if (cc_count > 0) {
2234 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;2241 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
2400 }2407 }
2401}2408}
2402 2409
2403static void mpeg_decode_gop(AVCodecContext *avctx,2410static int mpeg_decode_gop(AVCodecContext *avctx,
2404 const uint8_t *buf, int buf_size)2411 const uint8_t *buf, int buf_size)
2405{2412{
2406 Mpeg1Context *s1 = avctx->priv_data;2413 Mpeg1Context *s1 = avctx->priv_data;
@@ -2408,7 +2415,9 @@ static void mpeg_decode_gop(AVCodecContext *avctx, · 1 unmodified line
2408 int broken_link;2415 int broken_link;
2409 int64_t tc;2416 int64_t tc;
2410 2417
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;
2412 2421
2413 tc = s1->timecode_frame_start = get_bits(&s->gb, 25);2422 tc = s1->timecode_frame_start = get_bits(&s->gb, 25);
2414 2423
@@ -2425,6 +2434,8 @@ static void mpeg_decode_gop(AVCodecContext *avctx, · 10 unmodified lines
2425 "GOP (%s) closed_gop=%d broken_link=%d\n",2434 "GOP (%s) closed_gop=%d broken_link=%d\n",
2426 tcbuf, s1->closed_gop, broken_link);2435 tcbuf, s1->closed_gop, broken_link);
2427 }2436 }
2437
2438 return 0;
2428}2439}
2429 2440
2430static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,2441static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
@@ -2594,7 +2605,9 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 163 unmodified lines
2594 case GOP_START_CODE:2605 case GOP_START_CODE:
2595 if (last_code == 0) {2606 if (last_code == 0) {
2596 s2->first_field = 0;2607 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;
2598 s->sync = 1;2611 s->sync = 1;
2599 } else {2612 } else {
2600 av_log(avctx, AV_LOG_ERROR,2613 av_log(avctx, AV_LOG_ERROR,
@@ -2734,7 +2747,9 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 133 unmodified lines
2734 if (ret < 0)2747 if (ret < 0)
2735 return ret;2748 return ret;
2736 }2749 }
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;
2738 s->slice_count++;2753 s->slice_count++;
2739 }2754 }
2740 buf_ptr += 2; // FIXME add minimum number of bytes per slice2755 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