From 03dda13910572bcdfcd63a2a09fb65985587902a Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 20 Jun 2023 18:54:36 +0200 Subject: [PATCH] OpenALSoundManager: Fix a buffer overflow --- src/client/sound_openal_internal.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client/sound_openal_internal.cpp b/src/client/sound_openal_internal.cpp index 26890a074..5ab9e4c7c 100644 --- a/src/client/sound_openal_internal.cpp +++ b/src/client/sound_openal_internal.cpp @@ -730,10 +730,13 @@ f32 PlayingSound::getGain() noexcept void OpenALSoundManager::stepStreams(f32 dtime) { // spread work across steps - int num_issued_sounds = std::ceil(m_sounds_streaming_current_bigstep.size() - * dtime / m_stream_timer); + const size_t num_issued_sounds = std::min( + m_sounds_streaming_current_bigstep.size(), + (size_t)std::ceil(m_sounds_streaming_current_bigstep.size() + * dtime / m_stream_timer) + ); - for (; num_issued_sounds > 0; --num_issued_sounds) { + for (size_t i = 0; i < num_issued_sounds; ++i) { auto wptr = std::move(m_sounds_streaming_current_bigstep.back()); m_sounds_streaming_current_bigstep.pop_back();