瀏覽代碼

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.

Michael Wörner 1 年之前
父節點
當前提交
a4db4ae658
共有 1 個文件被更改,包括 8 次插入6 次删除
  1. 8 6
      modules/vorbis/resource_importer_ogg_vorbis.cpp

+ 8 - 6
modules/vorbis/resource_importer_ogg_vorbis.cpp

@@ -212,11 +212,13 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::load_from_buffer(const Vect
 				granule_pos = packet.granulepos;
 				granule_pos = packet.granulepos;
 			}
 			}
 
 
-			PackedByteArray data;
-			data.resize(packet.bytes);
-			memcpy(data.ptrw(), packet.packet, packet.bytes);
-			sorted_packets[granule_pos].push_back(data);
-			packet_count++;
+			if (packet.bytes > 0) {
+				PackedByteArray data;
+				data.resize(packet.bytes);
+				memcpy(data.ptrw(), packet.packet, packet.bytes);
+				sorted_packets[granule_pos].push_back(data);
+				packet_count++;
+			}
 		}
 		}
 		Vector<Vector<uint8_t>> packet_data;
 		Vector<Vector<uint8_t>> packet_data;
 		for (const KeyValue<uint64_t, Vector<Vector<uint8_t>>> &pair : sorted_packets) {
 		for (const KeyValue<uint64_t, Vector<Vector<uint8_t>>> &pair : sorted_packets) {
@@ -224,7 +226,7 @@ Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::load_from_buffer(const Vect
 				packet_data.push_back(packets);
 				packet_data.push_back(packets);
 			}
 			}
 		}
 		}
-		if (initialized_stream) {
+		if (initialized_stream && packet_data.size() > 0) {
 			ogg_packet_sequence->push_page(ogg_page_granulepos(&page), packet_data);
 			ogg_packet_sequence->push_page(ogg_page_granulepos(&page), packet_data);
 		}
 		}
 	}
 	}