From: Luca Barbato Date: Mon, 27 Apr 2015 23:55:10 +0000 (+0200) Subject: avresample: Reallocate the internal buffer to the correct size X-Git-Tag: v12_alpha1~1848 X-Git-Url: https://git.libav.org/?p=libav.git;a=commitdiff_plain;h=0ac8ff618c5e6d878c547a8877e714ed728950ce;hp=82de8d71118f4eafd6a43e9ea9169bd411793798 avresample: Reallocate the internal buffer to the correct size Fixes the corner case in which the internal buffer size is larger than input buffer provided and resizing it before moving the left over samples would make it write to now unallocated memory. Bug-Id: 825 CC: libav-stable@libav.org Signed-off-by: Luca Barbato --- diff --git a/libavresample/resample.c b/libavresample/resample.c index bf766a2b97..86a761b5d0 100644 --- a/libavresample/resample.c +++ b/libavresample/resample.c @@ -434,7 +434,9 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src) int bps = av_get_bytes_per_sample(c->avr->internal_sample_fmt); int i; - ret = ff_audio_data_realloc(c->buffer, in_samples + c->padding_size); + ret = ff_audio_data_realloc(c->buffer, + FFMAX(in_samples, in_leftover) + + c->padding_size); if (ret < 0) { av_log(c->avr, AV_LOG_ERROR, "Error reallocating resampling buffer\n"); return AVERROR(ENOMEM);