Skip to content

Commit a4db4ae

Browse files
committed
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.
1 parent 6bb89c7 commit a4db4ae

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

modules/vorbis/resource_importer_ogg_vorbis.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,21 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::load_from_buffer(const Vect
212212
granule_pos = packet.granulepos;
213213
}
214214

215-
PackedByteArray data;
216-
data.resize(packet.bytes);
217-
memcpy(data.ptrw(), packet.packet, packet.bytes);
218-
sorted_packets[granule_pos].push_back(data);
219-
packet_count++;
215+
if (packet.bytes > 0) {
216+
PackedByteArray data;
217+
data.resize(packet.bytes);
218+
memcpy(data.ptrw(), packet.packet, packet.bytes);
219+
sorted_packets[granule_pos].push_back(data);
220+
packet_count++;
221+
}
220222
}
221223
Vector<Vector<uint8_t>> packet_data;
222224
for (const KeyValue<uint64_t, Vector<Vector<uint8_t>>> &pair : sorted_packets) {
223225
for (const Vector<uint8_t> &packets : pair.value) {
224226
packet_data.push_back(packets);
225227
}
226228
}
227-
if (initialized_stream) {
229+
if (initialized_stream && packet_data.size() > 0) {
228230
ogg_packet_sequence->push_page(ogg_page_granulepos(&page), packet_data);
229231
}
230232
}

0 commit comments

Comments
 (0)