Skip to content

Commit

Permalink
Merge pull request godotengine#41921 from akien-mga/stb_vorbis-increa…
Browse files Browse the repository at this point in the history
…se-max-alloc

stb_vorbis: Increase max alloc buffer size for big Vorbis comments
  • Loading branch information
akien-mga authored Sep 9, 2020
2 parents 1ce46f2 + d16f5a5 commit 7015c59
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7015c59

Please sign in to comment.