jhiesey / videostream

Play html5 video when from a file-like object
MIT License
247 stars 73 forks source link

MP4Box.js returns invalid offset when given .mp3 file #9

Closed feross closed 8 years ago

feross commented 9 years ago

If you give videostream a file of the wrong type (like .mp3) it passes it to mp4box.js which doesn't realize that the file is not an MP4. It then asks for a crazy huge offset way bigger than the actual file length, which gets passed through to file.createReadStream({ start: xxx, end: xxx }) and fails.

Not a hugely important issue, since I shouldn't be giving it an .mp3, but just sharing since it would be nice if it was handled better.

jhiesey commented 8 years ago

Hm, now that the file length isn't a required field, not sure this is easy to fix. Thoughts?

feross commented 8 years ago

This isn't an issue for me anymore, since render-media doesn't ever pass .mp3 file data into videostream, but is there a way to detect that it's not a valid mp4 file?

Also, I'm curious, how does videostream avoid calling createReadStream() with invalid offsets? Pretty sure an invalid end value (i.e. too big) will cause webtorrent to throw an exception.

feross commented 8 years ago

I just fixed webtorrent to handle a really big end value more graceully, by clamping to the torrent.length - 1.