@@ -16,6 +16,7 @@ MP4.Atoms.visitChildren = function(parent, blob, context, callback, reader) {
1616 reader . onloadend = function ( ev ) {
1717 if ( ev . target . readyState === FileReader . DONE ) {
1818 if ( ev . target . result . byteLength < MP4 . Atoms . Atom . HeaderSize ) {
19+ context . error = new Error ( "Input data is corrupted or not encoded as mp4/mov" ) ;
1920 callback ( context ) ;
2021 return ;
2122 }
@@ -24,6 +25,7 @@ MP4.Atoms.visitChildren = function(parent, blob, context, callback, reader) {
2425
2526 var atom = new MP4 . Atoms . Atom ( data , 0 ) ;
2627 if ( atom . size < atom . headerSize ) {
28+ context . error = new Error ( "Input data is corrupted or not encoded as mp4/mov" ) ;
2729 callback ( context ) ;
2830 return ;
2931 }
@@ -62,16 +64,22 @@ MP4.Atoms.visitor = function(atom, blob, context, callback) {
6264 if ( ! atom . parsed ) {
6365 if ( MP4 . Atoms . Map [ atom . type ] . parser ) {
6466 var reader = new FileReader ( ) ;
67+ var parsedSize = MP4 . Atoms . Map [ atom . type ] . parsedSize == - 1 ? atom . size : MP4 . Atoms . Map [ atom . type ] . parsedSize ;
6568
6669 reader . onloadend = function ( ev ) {
6770 if ( ev . target . readyState === FileReader . DONE ) {
71+ if ( ev . target . result . byteLength < parsedSize ) {
72+ context . error = new Error ( "Input data is corrupted or not encoded as mp4/mov" ) ;
73+ callback ( context ) ;
74+ return ;
75+ }
76+
6877 var data = new DataView ( ev . target . result ) ;
6978 atom = MP4 . Atoms . Map [ atom . type ] . parser ( context , data , 0 ) ;
7079 MP4 . Atoms . visitChildren ( atom , blob , context , callback , reader ) ;
7180 }
7281 } ;
7382
74- var parsedSize = MP4 . Atoms . Map [ atom . type ] . parsedSize == - 1 ? atom . size : MP4 . Atoms . Map [ atom . type ] . parsedSize ;
7583 reader . readAsArrayBuffer ( blob . poll ( parsedSize ) ) ;
7684 } else {
7785 atom . dataSize = MP4 . Atoms . Map [ atom . type ] . parsedSize - atom . headerSize ;
0 commit comments