Skip to content

Commit

Permalink
Added a more informative error message when trying to import WAV file…
Browse files Browse the repository at this point in the history
…s with more than 2 GiB of data.

Fixed a possible overflow in AudioStreamWAV::set_data() when trying to set data with a size close to INT_MAX.
  • Loading branch information
bs-mwoerner committed Aug 22, 2024
1 parent 5ca419e commit 0fd4335
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion editor/import/resource_importer_wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s

/* chunk size */
uint32_t chunksize = file->get_32();
uint32_t file_pos = file->get_position(); //save file pos, so we can skip to next chunk safely
uint64_t file_pos = file->get_position(); //save file pos, so we can skip to next chunk safely

if (file->eof_reached()) {
//ERR_PRINT("EOF REACH");
Expand Down Expand Up @@ -197,6 +197,8 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
break;
}

ERR_FAIL_COND_V_MSG(chunksize > INT_MAX, ERR_INVALID_DATA, "WAV file '" + p_source_file + "' is too large (> 2 GiB of data). Try shortening or splitting it or use a compressed format such as Ogg Vorbis or MP3 instead.");

frames = chunksize;

if (format_channels == 0) {
Expand Down
6 changes: 3 additions & 3 deletions scene/resources/audio_stream_wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ void AudioStreamWAV::set_data(const Vector<uint8_t> &p_data) {
data_bytes = 0;
}

int datalen = p_data.size();
if (datalen) {
int64_t datalen = p_data.size();
if (datalen > 0 && datalen <= INT_MAX) {
const uint8_t *r = p_data.ptr();
int alloc_len = datalen + DATA_PAD * 2;
int64_t alloc_len = datalen + DATA_PAD * 2;
data = memalloc(alloc_len); //alloc with some padding for interpolation
memset(data, 0, alloc_len);
uint8_t *dataptr = (uint8_t *)data;
Expand Down

0 comments on commit 0fd4335

Please sign in to comment.