Fix crashes on unseekable or pure empty vorbis files

This commit is contained in:
Ralty
2025-08-06 04:54:25 +07:00
parent 549c1ad441
commit 16b080bf84
2 changed files with 19 additions and 2 deletions
@@ -372,7 +372,7 @@ class NativeAudioSource {
if (playing) {
var timeRemaining = (getLength() - value) / getPitch();
if (timeRemaining < 8) complete();
if (timeRemaining < 8 && value > 8) complete();
else {
completed = streamEnded = false;
if (streamed) {
+18 -1
View File
@@ -312,12 +312,29 @@ class AudioBuffer
if (vorbisFile == null) return null;
var info = vorbisFile.info();
if (info == null) return null;
var audioBuffer = new AudioBuffer();
audioBuffer.channels = info.channels;
audioBuffer.sampleRate = info.rate;
audioBuffer.bitsPerSample = 16;
audioBuffer.__srcVorbisFile = vorbisFile;
if (!vorbisFile.seekable() ||
vorbisFile.pcmTotal() < #if lime_cffi @:privateAccess lime._internal.backend.native.NativeAudioSource.STREAM_BUFFER_SAMPLES #else 0x4000 #end)
{
// convert it to static if its too short or unseekable.
vorbisFile.rawSeek(0);
var isBigEndian = lime.system.System.endianness == lime.system.Endian.BIG_ENDIAN;
var bytes:Bytes = Bytes.alloc(Std.int(haxe.Int64.toInt(vorbisFile.pcmTotal()) * info.channels * 2));
var total = 0, result = 0;
do {
total += (result = vorbisFile.read(bytes, total, 0x1000, isBigEndian, 2, true));
} while (result > 0);
audioBuffer.data = new UInt8Array(bytes);
}
else audioBuffer.__srcVorbisFile = vorbisFile;
return audioBuffer;
}