[FFmpeg-cvslog] avcodec/sonic: check memory allocations
Michael Niedermayer
git at videolan.org
Thu May 21 21:26:10 CEST 2015
ffmpeg | branch: release/2.5 | Michael Niedermayer <michaelni at gmx.at> | Fri May 15 17:26:25 2015 +0200| [43f9ec7113a4bc66d95a6b32e637221177d91fe6] | committer: Michael Niedermayer
avcodec/sonic: check memory allocations
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit c131a9fead5bf63215b6e1172b3c5c183cf90b85)
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43f9ec7113a4bc66d95a6b32e637221177d91fe6
---
libavcodec/sonic.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index a5e573a..81fe1ef 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -497,12 +497,15 @@ static int predictor_calc_error(int *k, int *state, int order, int error)
// copes better with quantization, and calculates the
// actual whitened result as it goes.
-static void modified_levinson_durbin(int *window, int window_entries,
+static int modified_levinson_durbin(int *window, int window_entries,
int *out, int out_entries, int channels, int *tap_quant)
{
int i;
int *state = av_calloc(window_entries, sizeof(*state));
+ if (!state)
+ return AVERROR(ENOMEM);
+
memcpy(state, window, 4* window_entries);
for (i = 0; i < out_entries; i++)
@@ -567,6 +570,7 @@ static void modified_levinson_durbin(int *window, int window_entries,
}
av_free(state);
+ return 0;
}
static inline int code_samplerate(int samplerate)
@@ -627,6 +631,9 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
// generate taps
s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
+ if (!s->tap_quant)
+ return AVERROR(ENOMEM);
+
for (i = 0; i < s->num_taps; i++)
s->tap_quant[i] = ff_sqrt(i+1);
@@ -656,7 +663,7 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
s->window_size = ((2*s->tail_size)+s->frame_size);
s->window = av_calloc(s->window_size, sizeof(*s->window));
- if (!s->window)
+ if (!s->window || !s->int_samples)
return AVERROR(ENOMEM);
avctx->extradata = av_mallocz(16);
@@ -769,8 +776,11 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i];
// generate taps
- modified_levinson_durbin(s->window, s->window_size,
+ ret = modified_levinson_durbin(s->window, s->window_size,
s->predictor_k, s->num_taps, s->channels, s->tap_quant);
+ if (ret < 0)
+ return ret;
+
if ((ret = intlist_write(&c, state, s->predictor_k, s->num_taps, 0)) < 0)
return ret;
@@ -913,6 +923,9 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
// generate taps
s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant));
+ if (!s->tap_quant)
+ return AVERROR(ENOMEM);
+
for (i = 0; i < s->num_taps; i++)
s->tap_quant[i] = ff_sqrt(i+1);
@@ -932,6 +945,8 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
}
s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples));
+ if (!s->int_samples)
+ return AVERROR(ENOMEM);
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
More information about the ffmpeg-cvslog
mailing list