avformat/rmdec: Simplify cleanup after read_header failure

by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/359/head
Andreas Rheinhardt 5 years ago
parent 5a58e58215
commit 48de45ea59
  1. 56
      libavformat/rmdec.c

@ -66,8 +66,6 @@ typedef struct RMDemuxContext {
int data_end; int data_end;
} RMDemuxContext; } RMDemuxContext;
static int rm_read_close(AVFormatContext *s);
static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len) static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
{ {
int read = avio_get_str(pb, len, buf, buf_size); int read = avio_get_str(pb, len, buf, buf_size);
@ -563,16 +561,15 @@ static int rm_read_header(AVFormatContext *s)
avio_skip(pb, tag_size - 8); avio_skip(pb, tag_size - 8);
for(;;) { for(;;) {
ret = AVERROR_INVALIDDATA;
if (avio_feof(pb)) if (avio_feof(pb))
goto fail; return AVERROR_INVALIDDATA;
tag = avio_rl32(pb); tag = avio_rl32(pb);
tag_size = avio_rb32(pb); tag_size = avio_rb32(pb);
avio_rb16(pb); avio_rb16(pb);
av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n", av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
av_fourcc2str(tag), tag_size); av_fourcc2str(tag), tag_size);
if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
goto fail; return AVERROR_INVALIDDATA;
switch(tag) { switch(tag) {
case MKTAG('P', 'R', 'O', 'P'): case MKTAG('P', 'R', 'O', 'P'):
/* file header */ /* file header */
@ -594,10 +591,8 @@ static int rm_read_header(AVFormatContext *s)
break; break;
case MKTAG('M', 'D', 'P', 'R'): case MKTAG('M', 'D', 'P', 'R'):
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) { if (!st)
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
}
st->id = avio_rb16(pb); st->id = avio_rb16(pb);
avio_rb32(pb); /* max bit rate */ avio_rb32(pb); /* max bit rate */
st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */ st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */
@ -614,10 +609,8 @@ static int rm_read_header(AVFormatContext *s)
get_str8(pb, mime, sizeof(mime)); /* mimetype */ get_str8(pb, mime, sizeof(mime)); /* mimetype */
st->codecpar->codec_type = AVMEDIA_TYPE_DATA; st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
st->priv_data = ff_rm_alloc_rmstream(); st->priv_data = ff_rm_alloc_rmstream();
if (!st->priv_data) { if (!st->priv_data)
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
}
size = avio_rb32(pb); size = avio_rb32(pb);
codec_pos = avio_tell(pb); codec_pos = avio_tell(pb);
@ -627,14 +620,14 @@ static int rm_read_header(AVFormatContext *s)
if (v == MKBETAG('M', 'L', 'T', 'I')) { if (v == MKBETAG('M', 'L', 'T', 'I')) {
ret = rm_read_multi(s, s->pb, st, mime); ret = rm_read_multi(s, s->pb, st, mime);
if (ret < 0) if (ret < 0)
goto fail; return ret;
avio_seek(pb, codec_pos + size, SEEK_SET); avio_seek(pb, codec_pos + size, SEEK_SET);
} else { } else {
avio_skip(pb, -4); avio_skip(pb, -4);
ret = ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data, ret = ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
size, mime); size, mime);
if (ret < 0) if (ret < 0)
goto fail; return ret;
} }
break; break;
@ -662,10 +655,6 @@ static int rm_read_header(AVFormatContext *s)
} }
return 0; return 0;
fail:
rm_read_close(s);
return ret;
} }
static int get_num(AVIOContext *pb, int *len) static int get_num(AVIOContext *pb, int *len)
@ -1153,6 +1142,7 @@ const AVInputFormat ff_rm_demuxer = {
.name = "rm", .name = "rm",
.long_name = NULL_IF_CONFIG_SMALL("RealMedia"), .long_name = NULL_IF_CONFIG_SMALL("RealMedia"),
.priv_data_size = sizeof(RMDemuxContext), .priv_data_size = sizeof(RMDemuxContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = rm_probe, .read_probe = rm_probe,
.read_header = rm_read_header, .read_header = rm_read_header,
.read_packet = rm_read_packet, .read_packet = rm_read_packet,
@ -1254,18 +1244,16 @@ static int ivr_read_header(AVFormatContext *s)
for (n = 0; n < nb_streams; n++) { for (n = 0; n < nb_streams; n++) {
if (!(st = avformat_new_stream(s, NULL)) || if (!(st = avformat_new_stream(s, NULL)) ||
!(st->priv_data = ff_rm_alloc_rmstream())) { !(st->priv_data = ff_rm_alloc_rmstream()))
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
}
if (avio_r8(pb) != 1) if (avio_r8(pb) != 1)
goto invalid_data; return AVERROR_INVALIDDATA;
count = avio_rb32(pb); count = avio_rb32(pb);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (avio_feof(pb)) if (avio_feof(pb))
goto invalid_data; return AVERROR_INVALIDDATA;
type = avio_r8(pb); type = avio_r8(pb);
tlen = avio_rb32(pb); tlen = avio_rb32(pb);
@ -1277,25 +1265,25 @@ static int ivr_read_header(AVFormatContext *s)
} else if (type == 4 && !strncmp(key, "OpaqueData", tlen)) { } else if (type == 4 && !strncmp(key, "OpaqueData", tlen)) {
ret = ffio_ensure_seekback(pb, 4); ret = ffio_ensure_seekback(pb, 4);
if (ret < 0) if (ret < 0)
goto fail; return ret;
if (avio_rb32(pb) == MKBETAG('M', 'L', 'T', 'I')) { if (avio_rb32(pb) == MKBETAG('M', 'L', 'T', 'I')) {
ret = rm_read_multi(s, pb, st, NULL); ret = rm_read_multi(s, pb, st, NULL);
} else { } else {
if (avio_feof(pb)) if (avio_feof(pb))
goto invalid_data; return AVERROR_INVALIDDATA;
avio_seek(pb, -4, SEEK_CUR); avio_seek(pb, -4, SEEK_CUR);
ret = ff_rm_read_mdpr_codecdata(s, pb, st, st->priv_data, len, NULL); ret = ff_rm_read_mdpr_codecdata(s, pb, st, st->priv_data, len, NULL);
} }
if (ret < 0) if (ret < 0)
goto fail; return ret;
} else if (type == 4) { } else if (type == 4) {
int j; int j;
av_log(s, AV_LOG_DEBUG, "%s = '0x", key); av_log(s, AV_LOG_DEBUG, "%s = '0x", key);
for (j = 0; j < len; j++) { for (j = 0; j < len; j++) {
if (avio_feof(pb)) if (avio_feof(pb))
goto invalid_data; return AVERROR_INVALIDDATA;
av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb)); av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb));
} }
av_log(s, AV_LOG_DEBUG, "'\n"); av_log(s, AV_LOG_DEBUG, "'\n");
@ -1312,19 +1300,14 @@ static int ivr_read_header(AVFormatContext *s)
} }
if (avio_r8(pb) != 6) if (avio_r8(pb) != 6)
goto invalid_data; return AVERROR_INVALIDDATA;
avio_skip(pb, 12); avio_skip(pb, 12);
avio_seek(pb, avio_rb64(pb) + pos, SEEK_SET); avio_seek(pb, avio_rb64(pb) + pos, SEEK_SET);
if (avio_r8(pb) != 8) if (avio_r8(pb) != 8)
goto invalid_data; return AVERROR_INVALIDDATA;
avio_skip(pb, 8); avio_skip(pb, 8);
return 0; return 0;
invalid_data:
ret = AVERROR_INVALIDDATA;
fail:
rm_read_close(s);
return ret;
} }
static int ivr_read_packet(AVFormatContext *s, AVPacket *pkt) static int ivr_read_packet(AVFormatContext *s, AVPacket *pkt)
@ -1412,6 +1395,7 @@ const AVInputFormat ff_ivr_demuxer = {
.name = "ivr", .name = "ivr",
.long_name = NULL_IF_CONFIG_SMALL("IVR (Internet Video Recording)"), .long_name = NULL_IF_CONFIG_SMALL("IVR (Internet Video Recording)"),
.priv_data_size = sizeof(RMDemuxContext), .priv_data_size = sizeof(RMDemuxContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = ivr_probe, .read_probe = ivr_probe,
.read_header = ivr_read_header, .read_header = ivr_read_header,
.read_packet = ivr_read_packet, .read_packet = ivr_read_packet,

Loading…
Cancel
Save