mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/brstm: Simplify cleanup after read_header failure
by setting the FF_FMT_INIT_CLEANUP flag. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
1500b7dfa5
commit
b10668dd61
|
@ -104,7 +104,6 @@ static int read_header(AVFormatContext *s)
|
||||||
int64_t h1offset, pos, toffset;
|
int64_t h1offset, pos, toffset;
|
||||||
uint32_t size, asize, start = 0;
|
uint32_t size, asize, start = 0;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int ret = AVERROR_EOF;
|
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
int bfstm = !strcmp("bfstm", s->iformat->name);
|
int bfstm = !strcmp("bfstm", s->iformat->name);
|
||||||
|
|
||||||
|
@ -288,30 +287,24 @@ static int read_header(AVFormatContext *s)
|
||||||
if (!bfstm)
|
if (!bfstm)
|
||||||
avio_skip(s->pb, pos + 16LL + b->offsets[ch].offset - avio_tell(s->pb));
|
avio_skip(s->pb, pos + 16LL + b->offsets[ch].offset - avio_tell(s->pb));
|
||||||
|
|
||||||
if (avio_read(s->pb, b->table + ch * 32, 32) != 32) {
|
if (avio_read(s->pb, b->table + ch * 32, 32) != 32)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bfstm)
|
if (bfstm)
|
||||||
avio_skip(s->pb, 14);
|
avio_skip(s->pb, 14);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < (avio_tell(s->pb) - pos)) {
|
if (size < (avio_tell(s->pb) - pos))
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
avio_skip(s->pb, size - (avio_tell(s->pb) - pos));
|
avio_skip(s->pb, size - (avio_tell(s->pb) - pos));
|
||||||
|
|
||||||
while (!avio_feof(s->pb)) {
|
while (!avio_feof(s->pb)) {
|
||||||
chunk = avio_rl32(s->pb);
|
chunk = avio_rl32(s->pb);
|
||||||
size = read32(s);
|
size = read32(s);
|
||||||
if (size < 8) {
|
if (size < 8)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
size -= 8;
|
size -= 8;
|
||||||
switch (chunk) {
|
switch (chunk) {
|
||||||
case MKTAG('S','E','E','K'):
|
case MKTAG('S','E','E','K'):
|
||||||
|
@ -321,19 +314,15 @@ static int read_header(AVFormatContext *s)
|
||||||
goto skip;
|
goto skip;
|
||||||
|
|
||||||
asize = b->block_count * st->codecpar->channels * 4;
|
asize = b->block_count * st->codecpar->channels * 4;
|
||||||
if (size < asize) {
|
if (size < asize)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (b->adpc) {
|
if (b->adpc) {
|
||||||
av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n");
|
av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n");
|
||||||
goto skip;
|
goto skip;
|
||||||
} else {
|
} else {
|
||||||
b->adpc = av_mallocz(asize);
|
b->adpc = av_mallocz(asize);
|
||||||
if (!b->adpc) {
|
if (!b->adpc)
|
||||||
ret = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (bfstm && codec != AV_CODEC_ID_ADPCM_THP_LE) {
|
if (bfstm && codec != AV_CODEC_ID_ADPCM_THP_LE) {
|
||||||
// Big-endian BFSTMs have little-endian SEEK tables
|
// Big-endian BFSTMs have little-endian SEEK tables
|
||||||
// for some strange reason.
|
// for some strange reason.
|
||||||
|
@ -351,10 +340,8 @@ static int read_header(AVFormatContext *s)
|
||||||
case MKTAG('D','A','T','A'):
|
case MKTAG('D','A','T','A'):
|
||||||
if ((start < avio_tell(s->pb)) ||
|
if ((start < avio_tell(s->pb)) ||
|
||||||
(!b->adpc && (codec == AV_CODEC_ID_ADPCM_THP ||
|
(!b->adpc && (codec == AV_CODEC_ID_ADPCM_THP ||
|
||||||
codec == AV_CODEC_ID_ADPCM_THP_LE))) {
|
codec == AV_CODEC_ID_ADPCM_THP_LE)))
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
avio_skip(s->pb, start - avio_tell(s->pb));
|
avio_skip(s->pb, start - avio_tell(s->pb));
|
||||||
|
|
||||||
if (bfstm && (codec == AV_CODEC_ID_ADPCM_THP ||
|
if (bfstm && (codec == AV_CODEC_ID_ADPCM_THP ||
|
||||||
|
@ -374,10 +361,7 @@ skip:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
return AVERROR_EOF;
|
||||||
read_close(s);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
|
@ -485,6 +469,7 @@ const AVInputFormat ff_brstm_demuxer = {
|
||||||
.name = "brstm",
|
.name = "brstm",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("BRSTM (Binary Revolution Stream)"),
|
.long_name = NULL_IF_CONFIG_SMALL("BRSTM (Binary Revolution Stream)"),
|
||||||
.priv_data_size = sizeof(BRSTMDemuxContext),
|
.priv_data_size = sizeof(BRSTMDemuxContext),
|
||||||
|
.flags_internal = FF_FMT_INIT_CLEANUP,
|
||||||
.read_probe = probe,
|
.read_probe = probe,
|
||||||
.read_header = read_header,
|
.read_header = read_header,
|
||||||
.read_packet = read_packet,
|
.read_packet = read_packet,
|
||||||
|
@ -497,6 +482,7 @@ const AVInputFormat ff_bfstm_demuxer = {
|
||||||
.name = "bfstm",
|
.name = "bfstm",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("BFSTM (Binary Cafe Stream)"),
|
.long_name = NULL_IF_CONFIG_SMALL("BFSTM (Binary Cafe Stream)"),
|
||||||
.priv_data_size = sizeof(BRSTMDemuxContext),
|
.priv_data_size = sizeof(BRSTMDemuxContext),
|
||||||
|
.flags_internal = FF_FMT_INIT_CLEANUP,
|
||||||
.read_probe = probe_bfstm,
|
.read_probe = probe_bfstm,
|
||||||
.read_header = read_header,
|
.read_header = read_header,
|
||||||
.read_packet = read_packet,
|
.read_packet = read_packet,
|
||||||
|
|
Loading…
Reference in New Issue