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