diff --git a/src/ogg/ogg-demuxer.ts b/src/ogg/ogg-demuxer.ts index c5164b9..0b4569f 100644 --- a/src/ogg/ogg-demuxer.ts +++ b/src/ogg/ogg-demuxer.ts @@ -322,6 +322,10 @@ export class OggDemuxer extends Demuxer { } const totalPacketSize = chunks.reduce((sum, chunk) => sum + chunk.length, 0); + if (totalPacketSize === 0) { + return null; // Invalid packet, treat it as end of stream + } + const packetData = new Uint8Array(totalPacketSize); let offset = 0; diff --git a/test/browser/ogg-demuxer.test.ts b/test/browser/ogg-demuxer.test.ts new file mode 100644 index 0000000..388da44 --- /dev/null +++ b/test/browser/ogg-demuxer.test.ts @@ -0,0 +1,26 @@ +import { expect, test } from 'vitest'; +import { Input } from '../../src/input.js'; +import { UrlSource } from '../../src/source.js'; +import { ALL_FORMATS } from '../../src/input-format.js'; +import { AudioBufferSink } from '../../src/media-sink.js'; +import { assert } from '../../src/misc.js'; + +// VLC creates OGG files with an empty EOS page, which previously caused decoding errors +test('can decode OGG Vorbis file with empty EOS page', async () => { + using input = new Input({ + source: new UrlSource('/vorbis-eos.ogg'), + formats: ALL_FORMATS, + }); + + const track = await input.getPrimaryAudioTrack(); + assert(track); + + const sink = new AudioBufferSink(track); + const buffers: AudioBuffer[] = []; + + for await (const { buffer } of sink.buffers(4, 10)) { + buffers.push(buffer); + } + + expect(buffers.length).toBeGreaterThan(0); +}); diff --git a/test/public/vorbis-eos.ogg b/test/public/vorbis-eos.ogg new file mode 100644 index 0000000..9a32d4f Binary files /dev/null and b/test/public/vorbis-eos.ogg differ