uploads: fix .mp4 filetype detection.

Fix a bug where MP4 files with major brand "iso4" weren't detected as
MP4, so they couldn't be uploaded.

This switches our MP4 detection code to something very similar to Firefox's
MP4 sniffing algorithm. Ours is slightly wrong because a) we only check
the major_brand, not the minor_brands, and b) we falsely detect certain 3GP
videos as MP4. 3GP is a very similar format to MP4, close enough that it
can be played by Chrome (but not Firefox), but it's technically not MP4
and should not have a .mp4 file extension. We leave it alone because we
have two existing 3GP media assets that were falsely detected as MP4.

https://danbooru.donmai.us/forum_topics/22356
https://github.com/mozilla/gecko-dev/blob/master/toolkit/components/mediasniffer/nsMediaSniffer.cpp#L78
https://mimesniff.spec.whatwg.org/#signature-for-mp4
This commit is contained in:
evazion
2022-10-28 03:41:13 -05:00
parent 6e685cdd42
commit 83ba91425f
5 changed files with 13 additions and 2 deletions

View File

@@ -372,8 +372,10 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should_upload_successfully("test/files/mp4/test-300x300.mp4")
should_upload_successfully("test/files/mp4/test-300x300-vp9.mp4")
should_upload_successfully("test/files/mp4/test-300x300-yuvj420p-h264.mp4")
should_upload_successfully("test/files/mp4/test-300x300-iso4.mp4")
should_upload_successfully("test/files/mp4/test-audio.mp4")
should_upload_successfully("test/files/mp4/test-audio.m4v")
should_upload_successfully("test/files/mp4/test-iso5.mp4")
should_upload_successfully("test/files/webm/test-512x512.webm")
should_upload_successfully("test/files/webm/test-gbrp-vp9.webm")
# should_upload_successfully("test/files/compressed.swf")