Skip to content

Commit

Permalink
Fix: Malformed MKV could cause an infinite loop
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
ItalyPaleAle and sindresorhus committed Jul 21, 2022
1 parent 3b08ab1 commit d868356
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Binary file added fixture/fixture-corrupt.mkv
Binary file not shown.
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/});
});

0 comments on commit d868356

Please sign in to comment.