From e1421715e85781de3250ac9b8ad224afa9b89275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20W=C3=B6rner?= Date: Tue, 16 Jan 2024 11:31:51 +0100 Subject: [PATCH] Fixed an issue that could cause a crash when encountering a zero-length packet in an OGG stream. A zero-length memcpy into a null pointer itself does not fail, but for gcc with optimizations, this can cause incorrect code to be generated further down the line since the pointer is then assumed to be non-null. Now stripping zero-length packets and pages without packets from the OggPacketSequence during import. This prevents various warning and error messages for files that end on a zero-length packet. (cherry picked from commit a4db4ae6581a6e4f051d8aea2c562c1165d22590) --- modules/vorbis/resource_importer_ogg_vorbis.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/vorbis/resource_importer_ogg_vorbis.cpp b/modules/vorbis/resource_importer_ogg_vorbis.cpp index 83927507984..8a095b0b74f 100644 --- a/modules/vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/vorbis/resource_importer_ogg_vorbis.cpp @@ -177,13 +177,15 @@ Ref ResourceImporterOggVorbis::import_ogg_vorbis(const Str } granule_pos = packet.granulepos; - PackedByteArray data; - data.resize(packet.bytes); - memcpy(data.ptrw(), packet.packet, packet.bytes); - packet_data.push_back(data); - packet_count++; + if (packet.bytes > 0) { + PackedByteArray data; + data.resize(packet.bytes); + memcpy(data.ptrw(), packet.packet, packet.bytes); + packet_data.push_back(data); + packet_count++; + } } - if (initialized_stream) { + if (initialized_stream && packet_data.size() > 0) { ogg_packet_sequence->push_page(granule_pos, packet_data); } }