mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
redspark: fix memleak in redspark_read_header
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
87888c043d
commit
d93bc4ef5c
@ -57,7 +57,7 @@ static int redspark_read_header(AVFormatContext *s)
|
|||||||
RedSparkContext *redspark = s->priv_data;
|
RedSparkContext *redspark = s->priv_data;
|
||||||
AVCodecContext *codec;
|
AVCodecContext *codec;
|
||||||
GetByteContext gbc;
|
GetByteContext gbc;
|
||||||
int i, coef_off;
|
int i, coef_off, ret = 0;
|
||||||
uint32_t key, data;
|
uint32_t key, data;
|
||||||
uint8_t *header, *pbc;
|
uint8_t *header, *pbc;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
@ -67,7 +67,7 @@ static int redspark_read_header(AVFormatContext *s)
|
|||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
codec = st->codec;
|
codec = st->codec;
|
||||||
|
|
||||||
header = av_malloc(HEADER_SIZE);
|
header = av_malloc(HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
if (!header)
|
if (!header)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
pbc = header;
|
pbc = header;
|
||||||
@ -91,15 +91,18 @@ static int redspark_read_header(AVFormatContext *s)
|
|||||||
codec->sample_rate = bytestream2_get_be32u(&gbc);
|
codec->sample_rate = bytestream2_get_be32u(&gbc);
|
||||||
if (codec->sample_rate <= 0 || codec->sample_rate > 96000) {
|
if (codec->sample_rate <= 0 || codec->sample_rate > 96000) {
|
||||||
av_log(s, AV_LOG_ERROR, "Invalid sample rate: %d\n", codec->sample_rate);
|
av_log(s, AV_LOG_ERROR, "Invalid sample rate: %d\n", codec->sample_rate);
|
||||||
return AVERROR_INVALIDDATA;
|
ret = AVERROR_INVALIDDATA;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
st->duration = bytestream2_get_be32u(&gbc) * 14;
|
st->duration = bytestream2_get_be32u(&gbc) * 14;
|
||||||
redspark->samples_count = 0;
|
redspark->samples_count = 0;
|
||||||
bytestream2_skipu(&gbc, 10);
|
bytestream2_skipu(&gbc, 10);
|
||||||
codec->channels = bytestream2_get_byteu(&gbc);
|
codec->channels = bytestream2_get_byteu(&gbc);
|
||||||
if (!codec->channels)
|
if (!codec->channels) {
|
||||||
return AVERROR_INVALIDDATA;
|
ret = AVERROR_INVALIDDATA;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
coef_off = 0x54 + codec->channels * 8;
|
coef_off = 0x54 + codec->channels * 8;
|
||||||
if (bytestream2_get_byteu(&gbc)) // Loop flag
|
if (bytestream2_get_byteu(&gbc)) // Loop flag
|
||||||
@ -107,20 +110,27 @@ static int redspark_read_header(AVFormatContext *s)
|
|||||||
|
|
||||||
codec->extradata_size = 32 * codec->channels;
|
codec->extradata_size = 32 * codec->channels;
|
||||||
codec->extradata = av_malloc(codec->extradata_size);
|
codec->extradata = av_malloc(codec->extradata_size);
|
||||||
if (!codec->extradata)
|
if (!codec->extradata) {
|
||||||
return AVERROR(ENOMEM);
|
ret = AVERROR(ENOMEM);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the ADPCM table */
|
/* Get the ADPCM table */
|
||||||
bytestream2_seek(&gbc, coef_off, SEEK_SET);
|
bytestream2_seek(&gbc, coef_off, SEEK_SET);
|
||||||
for (i = 0; i < codec->channels; i++) {
|
for (i = 0; i < codec->channels; i++) {
|
||||||
if (bytestream2_get_bufferu(&gbc, codec->extradata + i * 32, 32) != 32)
|
if (bytestream2_get_bufferu(&gbc, codec->extradata + i * 32, 32) != 32) {
|
||||||
return AVERROR_INVALIDDATA;
|
ret = AVERROR_INVALIDDATA;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
bytestream2_skipu(&gbc, 14);
|
bytestream2_skipu(&gbc, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
avpriv_set_pts_info(st, 64, 1, codec->sample_rate);
|
avpriv_set_pts_info(st, 64, 1, codec->sample_rate);
|
||||||
|
|
||||||
return 0;
|
fail:
|
||||||
|
av_free(header);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
|
Loading…
Reference in New Issue
Block a user