summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2022-02-15 00:25:02 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-02-15 00:25:02 +0800
commitb5badd12c627effa677de0a065172a000fa239f5 (patch)
tree9055d9a5341ca1df97962dd1d85bec70be5349d4 /modules
parent45428e91baf6298b978c632d313fd7944f26d74f (diff)
Fix crash and memory leak when importing OGG Vorbis
Diffstat (limited to 'modules')
-rw-r--r--modules/vorbis/resource_importer_ogg_vorbis.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/modules/vorbis/resource_importer_ogg_vorbis.cpp b/modules/vorbis/resource_importer_ogg_vorbis.cpp
index ccd463fd52..d12e65a96a 100644
--- a/modules/vorbis/resource_importer_ogg_vorbis.cpp
+++ b/modules/vorbis/resource_importer_ogg_vorbis.cpp
@@ -136,11 +136,11 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin
// Have a page now.
if (!initialized_stream) {
- ogg_stream_init(&stream_state, ogg_page_serialno(&page));
- ERR_FAIL_COND_V_MSG((err = ogg_stream_check(&stream_state)), Error::ERR_INVALID_DATA, "Ogg stream error " + itos(err));
+ if (ogg_stream_init(&stream_state, ogg_page_serialno(&page))) {
+ ERR_FAIL_V_MSG(Error::ERR_OUT_OF_MEMORY, "Failed allocating memory for OGG Vorbis stream.");
+ }
initialized_stream = true;
}
- ERR_FAIL_COND_V_MSG((err = ogg_stream_check(&stream_state)), Error::ERR_INVALID_DATA, "Ogg stream error " + itos(err));
ogg_stream_pagein(&stream_state, &page);
ERR_FAIL_COND_V_MSG((err = ogg_stream_check(&stream_state)), Error::ERR_INVALID_DATA, "Ogg stream error " + itos(err));
int desync_iters = 0;
@@ -160,10 +160,12 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin
break;
}
if (packet_count == 0 && vorbis_synthesis_idheader(&packet) == 0) {
- WARN_PRINT("Found a non-vorbis-header packet in a header position");
+ print_verbose("Found a non-vorbis-header packet in a header position");
// Clearly this logical stream is not a vorbis stream, so destroy it and try again with the next page.
- ogg_stream_destroy(&stream_state);
- initialized_stream = false;
+ if (initialized_stream) {
+ ogg_stream_clear(&stream_state);
+ initialized_stream = false;
+ }
break;
}
granule_pos = packet.granulepos;
@@ -178,6 +180,14 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin
ogg_packet_sequence->push_page(granule_pos, packet_data);
}
}
+ if (initialized_stream) {
+ ogg_stream_clear(&stream_state);
+ }
+ ogg_sync_clear(&sync_state);
+
+ if (ogg_packet_sequence->get_packet_granule_positions().is_empty()) {
+ ERR_FAIL_V_MSG(Error::ERR_FILE_CORRUPT, "OGG Vorbis decoding failed. Check that your data is a valid OGG Vorbis audio stream.");
+ }
ogg_vorbis_stream->set_packet_sequence(ogg_packet_sequence);
ogg_vorbis_stream->set_loop(loop);