Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 11110)
+++ wp-includes/post.php	(working copy)
@@ -1709,13 +1709,18 @@
 function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
 	global $wpdb, $wp_rewrite;
 	if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) {
-		$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $slug, $post_type, $post_ID, $post_parent));
+		if ( $post_type == 'page' ) {
+			$sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment') AND ID != %d AND post_parent = %d LIMIT 1";
+		} else {
+			$sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1";
+		}
+		$post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
 
 		if ($post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
 			$suffix = 2;
 			do {
 				$alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";
-				$post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
+				$post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent));
 				$suffix++;
 			} while ($post_name_check);
 			$slug = $alt_post_name;
