Problem/Motivation
When uploading a file with "0" (zero) as a part of its name, the file is marked incorrectly as application/octet-stream instead of its real mimetype.
This is because when the file name contains a "0" (zero) between dots, guessMimeType() from the ExtensionMimeTypeGuesser class returns NULL prematurely.
Steps to reproduce
- Have a file media entity.
- Upload a file named foo.0.zip. (No need to save the media entity.)
- Go to the Content > Files list.
- The uploaded file is marked as application/octet-stream instead of application/zip.
Proposed resolution
Fix the "while" condition in guessMimeType to exit only if array_shift returns NULL.
Remaining tasks
- Review the patch.
- Merge.
- Apply the patch to the latest core versions.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
Issue fork drupal-3487488
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dakwamineComment #4
smustgrave commentedThank you for reporting
So fixes actually need to land in the development branch first (11.x).
If still an issue on 11.x then it's still valid.
Next step then would be to add test coverage
Thanks
Comment #5
kim.pepperThis may be resolved with #3477346: ExtensionMimeTypeGuesser::guessMimeType returns less accurate MIME type when file extensions have multiple parts Are you able to test on 10.3.x?
Comment #6
kim.pepperAh looks like you did test on 10.3.x already. We will need a test to show the before and after with the fix.
Comment #7
kim.pepperRebased on 11.x, simplified the change, and added a test.
Confirmed the test-only pipeline failed:
Comment #8
mondrakecouple of comments inline
Comment #10
kim.pepperCreated a new MR because I don't know how to properly rebase via the gitlab UI. 😞
Comment #11
mondrakeone more nitpicking comment
Comment #12
mondrakeLooks good. Test coverage added.
Comment #14
mondrakeChanged the comment since my earlier suggestion duplicated the word 'because' and was not compliant to the 80 chars line limit.
I think I can leave that to RTBC.
Comment #15
dakwamineHello. :) The updated fix looks good for me. Much simpler indeed. :D Many thanks for the hard work.
Comment #16
mondrakeI think this should go in the upcoming point releases - it fixes a regression bug introduced by a MR not released yet in 10.4 and 11.1, and the bug leads to data corruption.
Comment #17
mondrakeComment #24
longwaveGreat find, thanks for the fix and test. The previous change was committed to 10.3 and 11.0 so backporting this all the way down to there as an eligible bug fix.
Committed and pushed 393baa761cc to 11.x and d83ba02ddbb to 11.1.x and bc5e491c885 to 11.0.x and 5c12effc9e3 to 10.5.x and e539d9bf68d to 10.4.x and 0475ceccefc to 10.3.x. Thanks!