From 36fa6369fca7c530bb9983f2da8454f5a06b5ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 9 Sep 2020 20:46:46 +0200 Subject: [PATCH] stb_vorbis: Increase max alloc buffer size for big Vorbis comments The previous max worked OK for audio data, but stb_vorbis recently gained support for Vorbis comments, which can embed up to 2^32-1 bytes of data (e.g. cover art encoded as base64). We use 2^30 as max which should be sufficient for most files. Fixes #41913. (cherry picked from commit d16f5a57c1882da245032b4543dbeb6d02931dbf) --- modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 606de8921bb..051679b2670 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -167,14 +167,16 @@ void AudioStreamOGGVorbis::clear_data() { void AudioStreamOGGVorbis::set_data(const PoolVector &p_data) { int src_data_len = p_data.size(); -#define MAX_TEST_MEM (1 << 20) - uint32_t alloc_try = 1024; PoolVector alloc_mem; PoolVector::Write w; stb_vorbis *ogg_stream = NULL; stb_vorbis_alloc ogg_alloc; + // Vorbis comments may be up to UINT32_MAX, but that's arguably pretty rare. + // Let's go with 2^30 so we don't risk going out of bounds. + const uint32_t MAX_TEST_MEM = 1 << 30; + while (alloc_try < MAX_TEST_MEM) { alloc_mem.resize(alloc_try); @@ -216,6 +218,8 @@ void AudioStreamOGGVorbis::set_data(const PoolVector &p_data) { break; } } + + ERR_FAIL_COND_MSG(alloc_try == MAX_TEST_MEM, vformat("Couldn't set vorbis data even with an alloc buffer of %d bytes, report bug.", MAX_TEST_MEM)); } PoolVector AudioStreamOGGVorbis::get_data() const {