mozilla / mp4parse-rust

Parser for ISO Base Media Format aka video/mp4 written in Rust.
Mozilla Public License 2.0
404 stars 62 forks source link

Allow skipped top-level boxes to extend past EOF. #393

Closed Zaggy1024 closed 1 year ago

Zaggy1024 commented 1 year ago

This allows files with garbage appended to the end to still load.

Fixes Firefox Bug #1814075.

This behavior isn't necessarily ideal, but other checks should fail if the file is unable to be parsed/decoded. The file in question as well as the test added here load successfully in Chrome,

Zaggy1024 commented 1 year ago

Replied in the review comment, but to summarize, after I investigated libavif, I'm satisfied this solution should be fine if you have anything to add. I'll make it skip errors for the skip_box_content() call while at EOF before merging though.

Zaggy1024 commented 1 year ago

@kinetiknz I've updated it with some new behavior that should be a lot more consistent at EOF. I made another test case and realized that read_box_header() had no way to signal that it ran out of data midway through parsing a header. This meant that the parser was already silently completing parsing on boxes that are smaller than their header requires. I've changed it to return an Option so that it can signal that, which allows me to detect EOF in the top-level parse and handle it based on strictness.

Hopefully that covers all your concerns, let me know if you need me to change anything!