I get a Undefined index (whatever the mime-type is) in get_extension_mimetype() (line 1230 of modules\media\media.module) error.

This happens because I entered an incorrect mime-type when attaching a file field to an entity, in its 'Allowed file extensions for uploaded files'. Perhaps this field should get some form of validation, or the media module must just do a few type checks, as in:

media.module (line 1230)
replace:
if ($id = $mimetype_mappings['extensions'][$extension]) {
return $mimetype_mappings['mimetypes'][$id];
}

with:
if (isset($mimetype_mappings['extensions'][$extension])) {
return $mimetype_mappings['mimetypes'][$mimetype_mappings['extensions'][$extension]];
}

and, media.media.inc (line 86)

replace :
foreach ($extensions as $extension) {
$mimetype = media_get_extension_mimetype($extension);
$mimetypes[] = $mimetype;
}

with:
foreach ($extensions as $extension) {
$mimetype = media_get_extension_mimetype($extension);
if ($mimetype) {
$mimetypes[] = $mimetype;
}
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

Thanks for the detailed report and suggested fix!

A patch to implement the suggestions with tweaks to the existing tests so that invalid file extensions are covered.

Devin Carlson’s picture

Status: Needs review » Fixed

Tested #1 with an existing site and was able to duplicate the problem and confirm that the patch fixed the undefined index warnings.

Committed #1 to Media 7.x-2.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.