Fixes: Timeout Fixes: 57281/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC1IMAGE_fuzzer-4594141064724480
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -836,6 +836,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 835 unmodified lines | ||
| 836 | 836 | const uint8_t *rawbuf; |
| 837 | 837 | int raw_size; |
| 838 | 838 | } *slices = NULL, *tmp; |
| 839 | + unsigned slices_allocated = 0; | |
| 839 | 840 | |
| 840 | 841 | v->second_field = 0; |
| 841 | 842 | |
| @@ -859,6 +860,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 17 unmodified lines | ||
| 859 | 860 | //for advanced profile we may need to parse and unescape data |
| 860 | 861 | if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { |
| 861 | 862 | int buf_size2 = 0; |
| 863 | + size_t next_allocated = 0; | |
| 862 | 864 | buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE); |
| 863 | 865 | if (!buf2) |
| 864 | 866 | return AVERROR(ENOMEM); |
| @@ -882,7 +884,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 17 unmodified lines | ||
| 882 | 884 | int buf_size3; |
| 883 | 885 | if (avctx->hwaccel) |
| 884 | 886 | buf_start_second_field = start; |
| 885 | − tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); | |
| 887 | + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); | |
| 888 | + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; | |
| 886 | 889 | if (!tmp) { |
| 887 | 890 | ret = AVERROR(ENOMEM); |
| 888 | 891 | goto err; |
| @@ -911,7 +914,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 22 unmodified lines | ||
| 911 | 914 | break; |
| 912 | 915 | case VC1_CODE_SLICE: { |
| 913 | 916 | int buf_size3; |
| 914 | − tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); | |
| 917 | + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); | |
| 918 | + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; | |
| 915 | 919 | if (!tmp) { |
| 916 | 920 | ret = AVERROR(ENOMEM); |
| 917 | 921 | goto err; |
| @@ -946,7 +950,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 28 unmodified lines | ||
| 946 | 950 | } else { // found field marker, unescape second field |
| 947 | 951 | if (avctx->hwaccel) |
| 948 | 952 | buf_start_second_field = divider; |
| 949 | − tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1); | |
| 953 | + av_size_mult(sizeof(*slices), n_slices+1, &next_allocated); | |
| 954 | + tmp = next_allocated ? av_fast_realloc(slices, &slices_allocated, next_allocated) : NULL; | |
| 950 | 955 | if (!tmp) { |
| 951 | 956 | ret = AVERROR(ENOMEM); |
| 952 | 957 | goto err; |