Mahara can't figure out mime types because of a finfo() bug
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mahara |
Fix Released
|
High
|
Robert Lyon | ||
1.6 |
Fix Released
|
High
|
Unassigned | ||
1.7 |
Fix Released
|
High
|
Unassigned | ||
1.8 |
Fix Released
|
High
|
Unassigned |
Bug Description
There have been several notable Mahara bugs based around the fact that our current handling of mimetypes is broken.
See for instance:
- https:/
- https:/
The problem is this:
1. You can't really trust the mimetype that the browser sends to you, because different browsers send different wacky things
2. Mahara has long used its own function file_mime_type() in lib/file.php for this purpose
3. file_mime_type() preferentially uses finfo() to check the mimetype. But, there's a bug in finfo() with an external magic db, which is how it is distributed on Ubuntu presently: https:/
4. file_mime_type() falls back to mime_content_
5. If neither of those works, we fall back to trusting what the browser told us, which isn't really the best (see #1)
Changed in mahara: | |
status: | Confirmed → In Progress |
Changed in mahara: | |
status: | In Progress → Fix Committed |
Changed in mahara: | |
milestone: | 1.10.0 → 1.9.0 |
no longer affects: | mahara/1.9 |
Changed in mahara: | |
status: | Fix Committed → Fix Released |
Since none of the standard PHP built-in's is acceptable at the moment for properly identifying a file's mimetype, I suggest we use Moodle's code for it. Moodle has a couple of functions in lib/filelib.php for identifying mime types based on file extension:
get_mimetypes_ array() : https:/ /github. com/moodle/ moodle/ blob/master/ lib/filelib. php#L1387
mimeinfo(): https:/ /github. com/moodle/ moodle/ blob/master/ lib/filelib. php#L1594
The get_mimetypes_ array() method has a pretty exhaustive list of mimetypes. The downside to this is that it's an external library, so we'll have to check periodically to keep it up to date. It would probably be best if this is just a temporary measure until the problems with PHP's mimetype functions get resolved.