Skip to content

Commit

Permalink
Fix infinite loop on a corrupted video file
Browse files Browse the repository at this point in the history
When the `moov` atom has the declared size more than is able to read,
the `parse` method ends up with the infinite while loop. This
modification fixes such an issue.
  • Loading branch information
gkozlenko committed May 24, 2024
1 parent 194a5e4 commit cc30f43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Gennady Kozlenko
Copyright (c) 2024 Gennady Kozlenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions lib/mp4/parser-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class ParserImpl {
this.moovAtom = new AtomMoov();
this.moovAtom.parse(buffer);
break;
} else {
throw new Error('Unable to read MOOV atom');
}
} else {
pos += atomSize;
Expand Down
12 changes: 12 additions & 0 deletions test/mp4-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ describe('MP4Parser', function () {
return expect(() => MP4Parser.parse(this.file)).to.throw('MOOV atom not found');
});
});

describe('when MOOV atom is not readable', function () {
before(function () {
this.buffer = Buffer.alloc(100);
this.buffer.writeUInt32BE(250, 0);
this.buffer.write('moov', 4);
});

it('should throws an error', function () {
return expect(() => MP4Parser.parse(this.buffer)).to.throw('Unable to read MOOV atom');
});
});
});

describe('#check', function () {
Expand Down

0 comments on commit cc30f43

Please sign in to comment.