Skip to content

Commit 9705ac4

Browse files
committed
Merge pull request #87246 from bs-mwoerner/ogg_crash
Fix a possible crash when importing an OGG file with zero-length packets
2 parents a1cc379 + a4db4ae commit 9705ac4

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)