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.
This commit is contained in:
Rémi Verschelde 2020-09-09 20:46:46 +02:00
parent 1ce46f2a3f
commit d16f5a57c1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 6 additions and 2 deletions

View File

@ -158,14 +158,16 @@ void AudioStreamOGGVorbis::clear_data() {
void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) {
int src_data_len = p_data.size();
#define MAX_TEST_MEM (1 << 20)
uint32_t alloc_try = 1024;
Vector<char> alloc_mem;
char *w;
stb_vorbis *ogg_stream = nullptr;
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);
w = alloc_mem.ptrw();
@ -205,6 +207,8 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &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));
}
Vector<uint8_t> AudioStreamOGGVorbis::get_data() const {