Fix #3615: Unsupported video codecs.

Don't allow uploading videos with unsupported video codecs.

The only video codecs we allow for MP4 files are H.264 and VP9. Other
codecs, including H.265 (aka HEVC), MPEG-4 part 2, and AV1, are
disallowed because they're not universally supported by browsers.
Firefox doesn't support H.265 or MPEG-4 part 2, and Safari doesn't
support AV1.

Additionally, don't allow videos with multiple video tracks, multiple
audio tracks, or no video tracks. Multiple video and audio tracks are
disallowed because they're rare and for moderation purposes, we don't
want people hiding content in extra tracks.

These restrictions really only apply to MP4 videos, since WebM files
don't support multiple video or audio tracks and only support a limited
number of codecs (VP8 and VP9 for videos, Vorbis and Opus for audio).

There are currently 22 posts with unsupported video codecs:

* https://danbooru.donmai.us/posts?tags=video+is:mp4+-exif:Track1:CompressorID=avc1+-exif:Track2:CompressorID=avc1+-exif:Track1:CompressorID=vp09+-exif:Track2:CompressorID=vp09 # AVC1 is H.264

There is one post that has multiple audio tracks:

* https://danbooru.donmai.us/posts/2382057
This commit is contained in:
evazion
2022-10-27 00:44:36 -05:00
parent 48ecb80d6b
commit a9d586e93a
11 changed files with 61 additions and 28 deletions

View File

@@ -241,6 +241,16 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
create_upload!("test/files/webm/test-512x512.mkv", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for a .mp4 file encoded with h265" do
create_upload!("test/files/mp4/test-300x300.h265.mp4", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for a .mp4 file encoded with av1" do
create_upload!("test/files/mp4/test-300x300.av1.mp4", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
end
context "for a video longer than the video length limit" do
@@ -334,10 +344,11 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should_upload_successfully("test/files/test.png")
should_upload_successfully("test/files/test-static-32x32.gif")
should_upload_successfully("test/files/test-animated-86x52.gif")
should_upload_successfully("test/files/test-300x300.mp4")
should_upload_successfully("test/files/test-audio.mp4")
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-audio.mp4")
should_upload_successfully("test/files/mp4/test-audio.m4v")
should_upload_successfully("test/files/webm/test-512x512.webm")
should_upload_successfully("test/files/test-audio.m4v")
# should_upload_successfully("test/files/compressed.swf")
should_upload_successfully("test/files/avif/fox.profile0.8bpc.yuv420.monochrome.avif")