WeTransfer / format_parser

file metadata parsing, done cheap
https://rubygems.org/gems/format_parser
Other
62 stars 18 forks source link

Improved stability for mp4 parser when dealing with corrupted FTYP boxes #241

Closed rcpalacio closed 12 months ago

rcpalacio commented 1 year ago

About the issue

Every MP4 file should start with a ftyp box. We rely on that to build a check for magic bytes and return early from the parser.

The problem arises when a file matches the header of a ftyp box but don't actually describe the box correctly -- for instance, bringing a wrong box size. In that case, the box can't be parsed and the file should be discarded. What happens instead is that, due to an issue with the safe navigation, the parser would still try to read from the missing box, resulting in the error NoMethodError: undefined method[]' for nil:NilClass`.