History

avcodec/vc1dec: Use av_fast_realloc() for slices

Fixes: Timeout Fixes: 57281/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC1IMAGE_fuzzer-4594141064724480

Michael Niedermayer committed 3 years ago

Commit c2ed9051 parent 1942dbb1 file · +8 −3Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/vc1dec.c+8−3
@@ -836,6 +836,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 835 unmodified lines
836836 const uint8_t *rawbuf;
837837 int raw_size;
838838 } *slices = NULL, *tmp;
839+ unsigned slices_allocated = 0;
839840
840841 v->second_field = 0;
841842
@@ -859,6 +860,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 17 unmodified lines
859860 //for advanced profile we may need to parse and unescape data
860861 if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
861862 int buf_size2 = 0;
863+ size_t next_allocated = 0;
862864 buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
863865 if (!buf2)
864866 return AVERROR(ENOMEM);
@@ -882,7 +884,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 17 unmodified lines
882884 int buf_size3;
883885 if (avctx->hwaccel)
884886 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;
886889 if (!tmp) {
887890 ret = AVERROR(ENOMEM);
888891 goto err;
@@ -911,7 +914,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 22 unmodified lines
911914 break;
912915 case VC1_CODE_SLICE: {
913916 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;
915919 if (!tmp) {
916920 ret = AVERROR(ENOMEM);
917921 goto err;
@@ -946,7 +950,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 28 unmodified lines
946950 } else { // found field marker, unescape second field
947951 if (avctx->hwaccel)
948952 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;
950955 if (!tmp) {
951956 ret = AVERROR(ENOMEM);
952957 goto err;

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