Skip to content

Commit d868356

Browse files
Fix: Malformed MKV could cause an infinite loop
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 3b08ab1 commit d868356

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ async function _fromTokenizer(tokenizer) {
681681
let mask = 0x80;
682682
let ic = 0; // 0 = A, 1 = B, 2 = C, 3 = D
683683

684-
while ((msb & mask) === 0) {
684+
while ((msb & mask) === 0 && mask !== 0) {
685685
++ic;
686686
mask >>= 1;
687687
}

fixture/fixture-corrupt.mkv

37.2 KB
Binary file not shown.

test.js

+5
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,8 @@ test('odd file sizes', async t => {
543543
await t.notThrowsAsync(FileType.fromStream(stream), `fromStream: File size: ${size} bytes`);
544544
}
545545
});
546+
547+
test('corrupt MKV throws', async t => {
548+
const filePath = path.join(__dirname, 'fixture/fixture-corrupt.mkv');
549+
await t.throwsAsync(FileType.fromFile(filePath), {message: /out of range/});
550+
});

0 commit comments

Comments
 (0)