avformat/icodec: 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:
Andreas Rheinhardt 2020-03-21 18:31:06 +01:00
parent 0a7e911108
commit 7a1037b6bd
1 changed files with 8 additions and 13 deletions

View File

@ -96,13 +96,11 @@ static int read_header(AVFormatContext *s)
int tmp; int tmp;
if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0) if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
goto fail; return AVERROR_INVALIDDATA;
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) { if (!st)
av_freep(&ico->images);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
}
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->width = avio_r8(pb); st->codecpar->width = avio_r8(pb);
@ -116,12 +114,12 @@ static int read_header(AVFormatContext *s)
ico->images[i].size = avio_rl32(pb); ico->images[i].size = avio_rl32(pb);
if (ico->images[i].size <= 0) { if (ico->images[i].size <= 0) {
av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size); av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size);
goto fail; return AVERROR_INVALIDDATA;
} }
ico->images[i].offset = avio_rl32(pb); ico->images[i].offset = avio_rl32(pb);
if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0) if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
goto fail; return AVERROR_INVALIDDATA;
codec = avio_rl32(pb); codec = avio_rl32(pb);
switch (codec) { switch (codec) {
@ -131,9 +129,8 @@ static int read_header(AVFormatContext *s)
st->codecpar->height = 0; st->codecpar->height = 0;
break; break;
case 40: case 40:
if (ico->images[i].size < 40) { if (ico->images[i].size < 40)
goto fail; return AVERROR_INVALIDDATA;
}
st->codecpar->codec_id = AV_CODEC_ID_BMP; st->codecpar->codec_id = AV_CODEC_ID_BMP;
tmp = avio_rl32(pb); tmp = avio_rl32(pb);
if (tmp) if (tmp)
@ -144,14 +141,11 @@ static int read_header(AVFormatContext *s)
break; break;
default: default:
avpriv_request_sample(s, "codec %d", codec); avpriv_request_sample(s, "codec %d", codec);
goto fail; return AVERROR_INVALIDDATA;
} }
} }
return 0; return 0;
fail:
av_freep(&ico->images);
return AVERROR_INVALIDDATA;
} }
static int read_packet(AVFormatContext *s, AVPacket *pkt) static int read_packet(AVFormatContext *s, AVPacket *pkt)
@ -224,6 +218,7 @@ const AVInputFormat ff_ico_demuxer = {
.name = "ico", .name = "ico",
.long_name = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"), .long_name = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"),
.priv_data_size = sizeof(IcoDemuxContext), .priv_data_size = sizeof(IcoDemuxContext),
.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,