Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 12777)
+++ wp-admin/includes/file.php	(working copy)
@@ -291,6 +291,35 @@
 	if ( $test_type ) {
 		$wp_filetype = wp_check_filetype( $file['name'], $mimes );
 
+		// If the file claims to be an image, validate it's extension
+		if ( function_exists('getimagesize') && !empty( $wp_filetype['type'] ) && 'image/' == substr( $wp_filetype['type'], 0, 6 ) && is_uploaded_file( $file['tmp_name'] ) ) {
+			// Get the image's true MIME
+			$imgstats = @getimagesize( $file['tmp_name'] );
+
+			// If the real MIME doesn't match the claimed MIME
+			if ( !empty($imgstats['mime']) && $imgstats['mime'] != $wp_filetype['type'] ) {
+				// Figure out what the extension should be
+				$mime_to_ext = apply_filters( 'image_mime_to_ext', array(
+					'image/jpeg' => 'jpg',
+					'image/png'  => 'png',
+					'image/gif'  => 'gif',
+					'image/bmp'  => 'bmp',
+					'image/tiff' => 'tif',
+				) );
+
+				// Replace whatever's after the last period in the filename with the correct extension
+				if ( !empty($mime_to_ext[$imgstats['mime']]) ) {
+					$filename_parts = explode( '.', $file['name'] );
+					array_pop( $filename_parts );
+					$filename_parts[] = $mime_to_ext[$imgstats['mime']];
+					$file['name'] = implode( '.', $filename_parts );
+
+					// Re-validate the extension / MIME
+					$wp_filetype = wp_check_filetype( $file['name'], $mimes );
+				}
+			}
+		}
+
 		extract( $wp_filetype );
 
 		if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
