Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.opus file is rejected; same file with .ogg file extension is accepted #18037

Closed
BenLubar opened this issue Apr 14, 2022 · 2 comments · Fixed by #28580
Closed

.opus file is rejected; same file with .ogg file extension is accepted #18037

BenLubar opened this issue Apr 14, 2022 · 2 comments · Fixed by #28580
Labels
area/media processing bug Something isn't working

Comments

@BenLubar
Copy link
Contributor

BenLubar commented Apr 14, 2022

Steps to reproduce the problem

  1. Upload an opus file to the post composer. Any file should work, example: repro.zip (GitHub won't let me upload a bare opus file)
  2. Rename the file to have a .ogg extension and try again. This time, it works.

Expected behaviour

both files should be accepted

Actual behaviour

uploading the file with the .opus extension results in a pop-up that says "422 Validation failed: File content type is invalid, File is invalid"

Specifications

Server:
https://github.com/mastodon/mastodon/tree/2287eebae0c1d699436a8cf3218d7cfe990a3605

Client:
Google Chrome 102.0.4975.0 (Official Build) dev (64-bit)
Revision 9637db21d4426d633aafd3a8117272c5b37bc672-refs/branch-heads/4975
Platform 14658.0.0 (Official Build) dev-channel edgar
Firmware Version Google_Edgar.7287.167.156

@BenLubar BenLubar added the bug Something isn't working label Apr 14, 2022
@PoneyClairDeLune
Copy link

Why does this issue still exist...

@vmstan
Copy link
Contributor

vmstan commented Jan 3, 2024

I think the issue is with the kt-paperclip Gem that handles upload processing.

Comparing the test file that @BenLubar attached, I can see from ffprobe how it is encoded:

vmstan@Sovereign ~/Code/mime-type $ ffprobe ~/Downloads/youre-a-girl.opus
...
Input #0, ogg, from '/Users/vmstan/Downloads/youre-a-girl.opus':
  Duration: 00:00:42.93, start: 0.000000, bitrate: 92 kb/s
  Stream #0:0(und): Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 libopus
      major_brand     : isom
      minor_version   : 512
      compatible_brands: isomiso2avc1mp41

Using the file utility, it's properly identified as an audio/ogg file in both variations.

vmstan@Sovereign ~/Code/mime-type $ file --mime ~/Downloads/youre-a-girl.opus
/Users/vmstan/Downloads/youre-a-girl.opus: audio/ogg; charset=binary
vmstan@Sovereign ~/Code/mime-type $ file --mime ~/Downloads/youre-a-girl.ogg
/Users/vmstan/Downloads/youre-a-girl.ogg: audio/ogg; charset=binary

However when using kt-paperclip to do the identification (I hacked together a basic script to invoke the Gem to do it, so it's not Mastodon code doing any part of the processing) it shows a different result based on the file names, both of which differ from audio/ogg

vmstan@Sovereign ~/Code/mime-type $ ruby get_mime_type.rb ~/Downloads/youre-a-girl.ogg
The MIME type of the file is: audio/vorbis
vmstan@Sovereign ~/Code/mime-type $ ruby get_mime_type.rb ~/Downloads/youre-a-girl.opus
The MIME type of the file is: audio/opus

In the Mastodon file app/models/concerns/attachmentable.rb there is a specific bypass for audio/vorbis files to bypass the kt-paperclip identification method and use file. I suspect it's necessary to add an exemption for audio/opus -- I will test and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/media processing bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants