History

avformat/avidec: Fix memleak when error happens after creating DV stream

Andreas Rheinhardt committed 6 years ago

Commit ea45d6e1 parent c7867b61 file · +17 −14Browse files

Unified · Split

libavformat/avidec.c+17−14
@@ -113,6 +113,7 @@ static const AVMetadataConv avi_metadata_conv[] = { · 112 unmodified lines
113 { 0 },113 { 0 },
114};114};
115 115
116static int avi_read_close(AVFormatContext *s);
116static int avi_load_index(AVFormatContext *s);117static int avi_load_index(AVFormatContext *s);
117static int guess_ni_flag(AVFormatContext *s);118static int guess_ni_flag(AVFormatContext *s);
118 119
@@ -464,6 +465,7 @@ static int calculate_bitrate(AVFormatContext *s) · 345 unmodified lines
464 return 1;465 return 1;
465}466}
466 467
468#define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
467static int avi_read_header(AVFormatContext *s)469static int avi_read_header(AVFormatContext *s)
468{470{
469 AVIContext *avi = s->priv_data;471 AVIContext *avi = s->priv_data;
@@ -499,7 +501,7 @@ static int avi_read_header(AVFormatContext *s) · 29 unmodified lines
499 frame_period = 0;501 frame_period = 0;
500 for (;;) {502 for (;;) {
501 if (avio_feof(pb))503 if (avio_feof(pb))
502 goto fail;504 RETURN_ERROR(AVERROR_INVALIDDATA);
503 tag = avio_rl32(pb);505 tag = avio_rl32(pb);
504 size = avio_rl32(pb);506 size = avio_rl32(pb);
505 507
@@ -571,12 +573,12 @@ static int avi_read_header(AVFormatContext *s) · 65 unmodified lines
571 stream_index++;573 stream_index++;
572 st = avformat_new_stream(s, NULL);574 st = avformat_new_stream(s, NULL);
573 if (!st)575 if (!st)
574 goto fail;576 RETURN_ERROR(AVERROR(ENOMEM));
575 577
576 st->id = stream_index;578 st->id = stream_index;
577 ast = av_mallocz(sizeof(AVIStream));579 ast = av_mallocz(sizeof(AVIStream));
578 if (!ast)580 if (!ast)
579 goto fail;581 RETURN_ERROR(AVERROR(ENOMEM));
580 st->priv_data = ast;582 st->priv_data = ast;
581 }583 }
582 if (amv_file_format)584 if (amv_file_format)
@@ -592,12 +594,12 @@ static int avi_read_header(AVFormatContext *s) · 9 unmodified lines
592 /* After some consideration -- I don't think we594 /* After some consideration -- I don't think we
593 * have to support anything but DV in type1 AVIs. */595 * have to support anything but DV in type1 AVIs. */
594 if (s->nb_streams != 1)596 if (s->nb_streams != 1)
595 goto fail;597 RETURN_ERROR(AVERROR_INVALIDDATA);
596 598
597 if (handler != MKTAG('d', 'v', 's', 'd') &&599 if (handler != MKTAG('d', 'v', 's', 'd') &&
598 handler != MKTAG('d', 'v', 'h', 'd') &&600 handler != MKTAG('d', 'v', 'h', 'd') &&
599 handler != MKTAG('d', 'v', 's', 'l'))601 handler != MKTAG('d', 'v', 's', 'l'))
600 goto fail;602 return AVERROR_INVALIDDATA;
601 603
602 if (!CONFIG_DV_DEMUXER)604 if (!CONFIG_DV_DEMUXER)
603 return AVERROR_DEMUXER_NOT_FOUND;605 return AVERROR_DEMUXER_NOT_FOUND;
@@ -697,7 +699,7 @@ static int avi_read_header(AVFormatContext *s) · 93 unmodified lines
697 "Invalid sample_size %d at stream %d\n",699 "Invalid sample_size %d at stream %d\n",
698 ast->sample_size,700 ast->sample_size,
699 stream_index);701 stream_index);
700 goto fail;702 RETURN_ERROR(AVERROR_INVALIDDATA);
701 }703 }
702 av_log(s, AV_LOG_WARNING,704 av_log(s, AV_LOG_WARNING,
703 "Invalid sample_size %d at stream %d "705 "Invalid sample_size %d at stream %d "
@@ -927,7 +929,7 @@ static int avi_read_header(AVFormatContext *s) · 223 unmodified lines
927 av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");929 av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
928 }930 }
929 if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)931 if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
930 return ret;932 goto fail;
931 }933 }
932 934
933 if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly935 if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
@@ -945,7 +947,7 @@ static int avi_read_header(AVFormatContext *s) · 11 unmodified lines
945 avi->use_odml &&947 avi->use_odml &&
946 read_odml_index(s, 0) < 0 &&948 read_odml_index(s, 0) < 0 &&
947 (s->error_recognition & AV_EF_EXPLODE))949 (s->error_recognition & AV_EF_EXPLODE))
948 goto fail;950 RETURN_ERROR(AVERROR_INVALIDDATA);
949 avio_seek(pb, pos + size, SEEK_SET);951 avio_seek(pb, pos + size, SEEK_SET);
950 break;952 break;
951 case MKTAG('v', 'p', 'r', 'p'):953 case MKTAG('v', 'p', 'r', 'p'):
@@ -980,7 +982,7 @@ static int avi_read_header(AVFormatContext *s) · 28 unmodified lines
980 if (s->nb_streams) {982 if (s->nb_streams) {
981 ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);983 ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
982 if (ret < 0)984 if (ret < 0)
983 return ret;985 goto fail;
984 break;986 break;
985 }987 }
986 default:988 default:
@@ -991,7 +993,7 @@ static int avi_read_header(AVFormatContext *s) · 4 unmodified lines
991 "I will ignore it and try to continue anyway.\n",993 "I will ignore it and try to continue anyway.\n",
992 av_fourcc2str(tag), size);994 av_fourcc2str(tag), size);
993 if (s->error_recognition & AV_EF_EXPLODE)995 if (s->error_recognition & AV_EF_EXPLODE)
994 goto fail;996 RETURN_ERROR(AVERROR_INVALIDDATA);
995 avi->movi_list = avio_tell(pb) - 4;997 avi->movi_list = avio_tell(pb) - 4;
996 avi->movi_end = avi->fsize;998 avi->movi_end = avi->fsize;
997 goto end_of_header;999 goto end_of_header;
@@ -1008,9 +1010,7 @@ static int avi_read_header(AVFormatContext *s) · 10 unmodified lines
1008end_of_header:1010end_of_header:
1009 /* check stream number */1011 /* check stream number */
1010 if (stream_index != s->nb_streams - 1) {1012 if (stream_index != s->nb_streams - 1) {
1011 1013 RETURN_ERROR(AVERROR_INVALIDDATA);
1012fail:
1013 return AVERROR_INVALIDDATA;
1014 }1014 }
1015 1015
1016 if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))1016 if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
@@ -1019,7 +1019,7 @@ fail: · 2 unmodified lines
1019 avi->index_loaded |= 1;1019 avi->index_loaded |= 1;
1020 1020
1021 if ((ret = guess_ni_flag(s)) < 0)1021 if ((ret = guess_ni_flag(s)) < 0)
1022 return ret;1022 goto fail;
1023 1023
1024 avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);1024 avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
1025 1025
@@ -1056,6 +1056,9 @@ fail: · 30 unmodified lines
1056 ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);1056 ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
1057 1057
1058 return 0;1058 return 0;
1059fail:
1060 avi_read_close(s);
1061 return ret;
1059}1062}
1060 1063
1061static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)1064static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)

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