mirror of https://git.ffmpeg.org/ffmpeg.git
shorten: Use separate pointers for the allocated memory for decoded samples.
Fixes invalid free() if any of the buffers are not allocated due to either not decoding a header or an error prior to allocating all buffers. Fixes CVE-2012-0858 CC: libav-stable@libav.org Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com> (cherry picked from commit204cb29b3c
) Signed-off-by: Reinhard Tartler <siretart@tauware.de> (cherry picked from commit6fc3287b9c
) Signed-off-by: Reinhard Tartler <siretart@tauware.de>
This commit is contained in:
parent
a207a2fecc
commit
96ed18cab1
|
@ -81,6 +81,7 @@ typedef struct ShortenContext {
|
||||||
int channels;
|
int channels;
|
||||||
|
|
||||||
int32_t *decoded[MAX_CHANNELS];
|
int32_t *decoded[MAX_CHANNELS];
|
||||||
|
int32_t *decoded_base[MAX_CHANNELS];
|
||||||
int32_t *offset[MAX_CHANNELS];
|
int32_t *offset[MAX_CHANNELS];
|
||||||
int *coeffs;
|
int *coeffs;
|
||||||
uint8_t *bitstream;
|
uint8_t *bitstream;
|
||||||
|
@ -130,13 +131,14 @@ static int allocate_buffers(ShortenContext *s)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
s->offset[chan] = tmp_ptr;
|
s->offset[chan] = tmp_ptr;
|
||||||
|
|
||||||
tmp_ptr = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
|
tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
|
||||||
|
sizeof(s->decoded_base[0][0]));
|
||||||
if (!tmp_ptr)
|
if (!tmp_ptr)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
s->decoded[chan] = tmp_ptr;
|
s->decoded_base[chan] = tmp_ptr;
|
||||||
for (i=0; i<s->nwrap; i++)
|
for (i=0; i<s->nwrap; i++)
|
||||||
s->decoded[chan][i] = 0;
|
s->decoded_base[chan][i] = 0;
|
||||||
s->decoded[chan] += s->nwrap;
|
s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
|
coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
|
||||||
|
@ -542,8 +544,8 @@ static av_cold int shorten_decode_close(AVCodecContext *avctx)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < s->channels; i++) {
|
for (i = 0; i < s->channels; i++) {
|
||||||
s->decoded[i] -= s->nwrap;
|
s->decoded[i] = NULL;
|
||||||
av_freep(&s->decoded[i]);
|
av_freep(&s->decoded_base[i]);
|
||||||
av_freep(&s->offset[i]);
|
av_freep(&s->offset[i]);
|
||||||
}
|
}
|
||||||
av_freep(&s->bitstream);
|
av_freep(&s->bitstream);
|
||||||
|
|
Loading…
Reference in New Issue