mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
(Audio Mixer) Pad sample buffers to prevent potential heap-buffer-overflows when resampling (fixes crash when using 30 kHz menu audio files) (#12987)
This commit is contained in:
parent
868a4bf3fc
commit
516dcb34d9
@ -279,17 +279,15 @@ static bool one_shot_resample(const float* in, size_t samples_in,
|
|||||||
resampler_ident, quality, ratio))
|
resampler_ident, quality, ratio))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*
|
/* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
|
||||||
* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
|
|
||||||
* add four more samples in the formula below just as safeguard, because
|
* add four more samples in the formula below just as safeguard, because
|
||||||
* resampler->process sometimes reports more output samples than the
|
* resampler->process sometimes reports more output samples than the
|
||||||
* formula below calculates. Ideally, audio resamplers should have a
|
* formula below calculates. Ideally, audio resamplers should have a
|
||||||
* function to return the number of samples they will output given a
|
* function to return the number of samples they will output given a
|
||||||
* count of input samples.
|
* count of input samples. */
|
||||||
*/
|
*samples_out = (size_t)(samples_in * ratio);
|
||||||
*samples_out = samples_in * ratio + 4;
|
|
||||||
*out = (float*)memalign_alloc(16,
|
*out = (float*)memalign_alloc(16,
|
||||||
((*samples_out + 15) & ~15) * sizeof(float));
|
(((*samples_out + 4) + 15) & ~15) * sizeof(float));
|
||||||
|
|
||||||
if (*out == NULL)
|
if (*out == NULL)
|
||||||
return false;
|
return false;
|
||||||
@ -547,9 +545,15 @@ static bool audio_mixer_play_ogg(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
|
||||||
|
* add four more samples in the formula below just as safeguard, because
|
||||||
|
* resampler->process sometimes reports more output samples than the
|
||||||
|
* formula below calculates. Ideally, audio resamplers should have a
|
||||||
|
* function to return the number of samples they will output given a
|
||||||
|
* count of input samples. */
|
||||||
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
||||||
ogg_buffer = (float*)memalign_alloc(16,
|
ogg_buffer = (float*)memalign_alloc(16,
|
||||||
((samples + 15) & ~15) * sizeof(float));
|
(((samples + 4) + 15) & ~15) * sizeof(float));
|
||||||
|
|
||||||
if (!ogg_buffer)
|
if (!ogg_buffer)
|
||||||
{
|
{
|
||||||
@ -690,9 +694,15 @@ static bool audio_mixer_play_flac(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
|
||||||
|
* add four more samples in the formula below just as safeguard, because
|
||||||
|
* resampler->process sometimes reports more output samples than the
|
||||||
|
* formula below calculates. Ideally, audio resamplers should have a
|
||||||
|
* function to return the number of samples they will output given a
|
||||||
|
* count of input samples. */
|
||||||
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
||||||
flac_buffer = (float*)memalign_alloc(16,
|
flac_buffer = (float*)memalign_alloc(16,
|
||||||
((samples + 15) & ~15) * sizeof(float));
|
(((samples + 4) + 15) & ~15) * sizeof(float));
|
||||||
|
|
||||||
if (!flac_buffer)
|
if (!flac_buffer)
|
||||||
{
|
{
|
||||||
@ -762,9 +772,15 @@ static bool audio_mixer_play_mp3(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocate on a 16-byte boundary, and pad to a multiple of 16 bytes. We
|
||||||
|
* add four more samples in the formula below just as safeguard, because
|
||||||
|
* resampler->process sometimes reports more output samples than the
|
||||||
|
* formula below calculates. Ideally, audio resamplers should have a
|
||||||
|
* function to return the number of samples they will output given a
|
||||||
|
* count of input samples. */
|
||||||
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
samples = (unsigned)(AUDIO_MIXER_TEMP_BUFFER * ratio);
|
||||||
mp3_buffer = (float*)memalign_alloc(16,
|
mp3_buffer = (float*)memalign_alloc(16,
|
||||||
((samples + 15) & ~15) * sizeof(float));
|
(((samples + 4) + 15) & ~15) * sizeof(float));
|
||||||
|
|
||||||
if (!mp3_buffer)
|
if (!mp3_buffer)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user