Page MenuHomePhabricator

MediaWiki confused over mime-type of exe files
Closed, DuplicatePublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • use maintenance/importImages.php to import an exe file, e.g. php importImages.php /yourfolderhere --extensions=exe
  • find it in your mediawiki installation, try to move it, notice the failure

What happens?:

  • it fails because during the move the file is recognized as application/octet-stream, while during import it was stored in the database as unknown/unknown, and mediawiki doesn't accept this mismatch
  • importImages.php uses the function guessMimeType() in /includes/libs/mime/MimeAnalyzer.php to first recognize it as application/octet-stream... (line 590)
  • ... but subsequently it uses the function improveTypeFromExtension(), which in turn uses /includes/libs/mime/MimeMap.php, to in the end re-map application/octet-stream to unknown/unknown (line 465)
  • meanwhile the move function keeps the file identified as application/octet-stream

What should have happened instead?:

  • that's the big question... because this is actually an old issue, see https://phabricator.wikimedia.org/T247348
  • the suggested commit from that old ticket was never merged by the look of it (as is now irrelevant because it seems llike the mime libs have changed quite a bit)
  • and the proposed solution there didn't fix this problem, because identifying exe files as application/vnd.microsoft.portable-executable still breaks the move for the same reason as mentioned above
  • my suggestion: simply remove 'application/octet-stream' => 'unknown/unknown', (line 465) from /includes/libs/mime/MimeMap.php - nothing more
  • I've tested that, it solves this problem

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc.:
version 1.37.1

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

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.