Commit 5171e0ee authored by Andreas Rheinhardt's avatar Andreas Rheinhardt

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: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 3d3ba43bc68ca90fe72d0fc390c9e5f5c7de1513)
parent 245d0f18
...@@ -79,6 +79,13 @@ typedef struct OMAContext { ...@@ -79,6 +79,13 @@ typedef struct OMAContext {
int (*read_packet)(AVFormatContext *s, AVPacket *pkt); int (*read_packet)(AVFormatContext *s, AVPacket *pkt);
} OMAContext; } 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, static void hex_log(AVFormatContext *s, int level,
const char *name, const uint8_t *value, int len) const char *name, const uint8_t *value, int len)
{ {
...@@ -402,11 +409,14 @@ static int oma_read_header(AVFormatContext *s) ...@@ -402,11 +409,14 @@ static int oma_read_header(AVFormatContext *s)
} }
ret = avio_read(s->pb, buf, EA3_HEADER_SIZE); 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; return -1;
}
if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}), 3) || if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}), 3) ||
buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) { 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"); av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -425,8 +435,10 @@ static int oma_read_header(AVFormatContext *s) ...@@ -425,8 +435,10 @@ static int oma_read_header(AVFormatContext *s)
codec_params = AV_RB24(&buf[33]); codec_params = AV_RB24(&buf[33]);
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) if (!st) {
return AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail;
}
st->start_time = 0; st->start_time = 0;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
...@@ -441,7 +453,8 @@ static int oma_read_header(AVFormatContext *s) ...@@ -441,7 +453,8 @@ static int oma_read_header(AVFormatContext *s)
samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100; samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
if (!samplerate) { if (!samplerate) {
av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n"); av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n");
return AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail;
} }
if (samplerate != 44100) if (samplerate != 44100)
avpriv_request_sample(s, "Sample rate %d", samplerate); avpriv_request_sample(s, "Sample rate %d", samplerate);
...@@ -459,7 +472,7 @@ static int oma_read_header(AVFormatContext *s) ...@@ -459,7 +472,7 @@ static int oma_read_header(AVFormatContext *s)
/* fake the ATRAC3 extradata /* fake the ATRAC3 extradata
* (wav format, makes stream copy to wav work) */ * (wav format, makes stream copy to wav work) */
if ((ret = ff_alloc_extradata(st->codecpar, 14)) < 0) if ((ret = ff_alloc_extradata(st->codecpar, 14)) < 0)
return ret; goto fail;
edata = st->codecpar->extradata; edata = st->codecpar->extradata;
AV_WL16(&edata[0], 1); // always 1 AV_WL16(&edata[0], 1); // always 1
...@@ -476,7 +489,8 @@ static int oma_read_header(AVFormatContext *s) ...@@ -476,7 +489,8 @@ static int oma_read_header(AVFormatContext *s)
if (!channel_id) { if (!channel_id) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id); "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->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1];
st->codecpar->channels = ff_oma_chid_to_num_channels[channel_id - 1]; st->codecpar->channels = ff_oma_chid_to_num_channels[channel_id - 1];
...@@ -484,7 +498,8 @@ static int oma_read_header(AVFormatContext *s) ...@@ -484,7 +498,8 @@ static int oma_read_header(AVFormatContext *s)
samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100; samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
if (!samplerate) { if (!samplerate) {
av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n"); 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->sample_rate = samplerate;
st->codecpar->bit_rate = samplerate * framesize / (2048 / 8); st->codecpar->bit_rate = samplerate * framesize / (2048 / 8);
...@@ -524,12 +539,16 @@ static int oma_read_header(AVFormatContext *s) ...@@ -524,12 +539,16 @@ static int oma_read_header(AVFormatContext *s)
break; break;
default: default:
av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]); 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; st->codecpar->block_align = framesize;
return 0; return 0;
fail:
oma_read_close(s);
return ret;
} }
static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) static int oma_read_packet(AVFormatContext *s, AVPacket *pkt)
...@@ -591,13 +610,6 @@ wipe: ...@@ -591,13 +610,6 @@ wipe:
return err; 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 = { AVInputFormat ff_oma_demuxer = {
.name = "oma", .name = "oma",
.long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"), .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment