diff --git a/core.js b/core.js index f5e16796..d653e66a 100644 --- a/core.js +++ b/core.js @@ -681,7 +681,7 @@ async function _fromTokenizer(tokenizer) { let mask = 0x80; let ic = 0; // 0 = A, 1 = B, 2 = C, 3 = D - while ((msb & mask) === 0) { + while ((msb & mask) === 0 && mask !== 0) { ++ic; mask >>= 1; } diff --git a/fixture/fixture-corrupt.mkv b/fixture/fixture-corrupt.mkv new file mode 100644 index 00000000..31d6184e Binary files /dev/null and b/fixture/fixture-corrupt.mkv differ diff --git a/test.js b/test.js index 7d729b76..ffeea053 100644 --- a/test.js +++ b/test.js @@ -543,3 +543,8 @@ test('odd file sizes', async t => { await t.notThrowsAsync(FileType.fromStream(stream), `fromStream: File size: ${size} bytes`); } }); + +test('corrupt MKV throws', async t => { + const filePath = path.join(__dirname, 'fixture/fixture-corrupt.mkv'); + await t.throwsAsync(FileType.fromFile(filePath), {message: /out of range/}); +});