Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 12773)
+++ wp-admin/includes/file.php	(working copy)
@@ -293,6 +293,32 @@
 
 		extract( $wp_filetype );
 
+		// If the file claims to be an image, validate it's extension
+		if ( 'image/' == substr( $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'] != $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 );
+				}
+			}
+		}
+
 		if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
 			return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
 
