Page MenuHomePhabricator

MediaWiki does not correctly recognize the mime type of exe files
Open, LowPublic

Description

Steps to reproduce:

  • Use importImages.php to import an exe file.

Expected behaviour:

  • MediaWiki reports a mime type of application/octet-stream [ application/vnd.microsoft.portable-executable would be better, but current code does octet-stream]

Actual behaviour:

  • MediaWiki reports unknown/unknown.

MediaWiki has code that looks for both .exe extension and MZ magic numbers. It should be able to detect this (The detection is also used as part of the blacklist, so that presumably isn't working either for these file types)

Details

Related Changes in Gerrit:

Event Timeline

The answer is because unknown/unknown is set as the canonical alias for application/octet-stream (In buildin mime types but not in mime.types file). That seems wrong.

Its been that way since 27105c21295 so i guess this has always been broken

Change 579881 had a related patch set uploaded (by Brian Wolff; owner: Brian Wolff):
[mediawiki/core@master] Make mime recognizer recognize exe files.

https://gerrit.wikimedia.org/r/579881

Patches for this are welcome. @Llanddewi I believe you may be interested in this. There is a patch already with code that afaik is in fairly good shape but needs to be rebased and has a failing test. Feel free to rebase it and/or re-create as a new patch.

Based on chatting with @tstarling, I think we're fine with owning and maintaining support for detecting EXE files properly in MediaWiki.

The detection logic for its "magic header" binary code already exists but is currently explicitly mapped to octet-stream. I had mistakenly thought it got there by means of a fallback but it is fact explicitly mapped there:

MineAnalyzer.php
'MZ'               => 'application/octet-stream', // DOS/Windows executable

I'm merging this into task T247348, with the understanding that if this correctly recognises it as a distinct type and if that type isn't considered "unknown" that the issue you found is also naturally avoided/resolved.

Krinkle removed a project: Performance-Team.
Krinkle added a project: Performance-Team.
Krinkle edited projects, added: patch-welcome; removed: Patch-For-Review.

Change #579881 abandoned by Hashar:

[mediawiki/core@master] Make mime recognizer recognize exe files.

https://gerrit.wikimedia.org/r/579881

Change #579881 restored by Thcipriani:

[mediawiki/core@master] Make mime recognizer recognize exe files.

https://gerrit.wikimedia.org/r/579881