aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-06-14 00:24:55 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-07-03 16:14:48 +0200
commit3174c7b1bf3088117cd8403e1ab6f0b26b1111df (patch)
treee3b8b723dc369e36e5e178d54a58afa4ef6c3d8b
parentcfe31c7f487b595fdf94e9bff16d6ef5fb7a5d7a (diff)
downloadffmpeg-3174c7b1bf3088117cd8403e1ab6f0b26b1111df.tar.gz
avformat/omadec: Fix memleaks upon read_header failure
Fixes possible leaks of id3v2 metadata as well as an AVDES struct in case the content is encrypted and an error happens lateron. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit 3d3ba43bc68ca90fe72d0fc390c9e5f5c7de1513) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--libavformat/omadec.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/libavformat/omadec.c b/libavformat/omadec.c
index 6e476dbf25..d8ddffdaae 100644
--- a/libavformat/omadec.c
+++ b/libavformat/omadec.c
@@ -77,6 +77,13 @@ typedef struct OMAContext {
struct AVDES *av_des;
} OMAContext;
+static int oma_read_close(AVFormatContext *s)
+{
+ OMAContext *oc = s->priv_data;
+ av_freep(&oc->av_des);
+ return 0;
+}
+
static void hex_log(AVFormatContext *s, int level,
const char *name, const uint8_t *value, int len)
{
@@ -315,11 +322,14 @@ static int oma_read_header(AVFormatContext *s)
ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta, 0);
ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
- if (ret < EA3_HEADER_SIZE)
+ if (ret < EA3_HEADER_SIZE) {
+ ff_id3v2_free_extra_meta(&extra_meta);
return -1;
+ }
if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}), 3) ||
buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) {
+ ff_id3v2_free_extra_meta(&extra_meta);
av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n");
return AVERROR_INVALIDDATA;
}
@@ -338,8 +348,10 @@ static int oma_read_header(AVFormatContext *s)
codec_params = AV_RB24(&buf[33]);
st = avformat_new_stream(s, NULL);
- if (!st)
- return AVERROR(ENOMEM);
+ if (!st) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
st->start_time = 0;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -352,7 +364,8 @@ static int oma_read_header(AVFormatContext *s)
samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
if (!samplerate) {
av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
}
if (samplerate != 44100)
avpriv_request_sample(s, "Sample rate %d", samplerate);
@@ -369,8 +382,8 @@ static int oma_read_header(AVFormatContext *s)
/* fake the ATRAC3 extradata
* (wav format, makes stream copy to wav work) */
- if (ff_alloc_extradata(st->codecpar, 14))
- return AVERROR(ENOMEM);
+ if ((ret = ff_alloc_extradata(st->codecpar, 14)) < 0)
+ goto fail;
edata = st->codecpar->extradata;
AV_WL16(&edata[0], 1); // always 1
@@ -387,7 +400,8 @@ static int oma_read_header(AVFormatContext *s)
if (!channel_id) {
av_log(s, AV_LOG_ERROR,
"Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id);
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
}
st->codecpar->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
st->codecpar->channels = ff_oma_chid_to_num_channels[channel_id - 1];
@@ -395,7 +409,8 @@ static int oma_read_header(AVFormatContext *s)
samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
if (!samplerate) {
av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
}
st->codecpar->sample_rate = samplerate;
st->codecpar->bit_rate = samplerate * framesize * 8 / 2048;
@@ -419,12 +434,16 @@ static int oma_read_header(AVFormatContext *s)
break;
default:
av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]);
- return AVERROR(ENOSYS);
+ ret = AVERROR(ENOSYS);
+ goto fail;
}
st->codecpar->block_align = framesize;
return 0;
+fail:
+ oma_read_close(s);
+ return ret;
}
@@ -513,13 +532,6 @@ wipe:
return err;
}
-static int oma_read_close(AVFormatContext *s)
-{
- OMAContext *oc = s->priv_data;
- av_free(oc->av_des);
- return 0;
-}
-
AVInputFormat ff_oma_demuxer = {
.name = "oma",
.long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),