Index: wp-includes/version.php
===================================================================
--- wp-includes/version.php	(revision 11201)
+++ wp-includes/version.php	(working copy)
@@ -15,6 +15,6 @@
  *
  * @global int $wp_db_version
  */
-$wp_db_version = 10850;
+$wp_db_version = 11200;
 
 ?>
Index: wp-admin/includes/upgrade.php
===================================================================
--- wp-admin/includes/upgrade.php	(revision 11201)
+++ wp-admin/includes/upgrade.php	(working copy)
@@ -340,7 +340,7 @@
 	if ( $wp_current_db_version < 8989 )
 		upgrade_270();
 
-	if ( $wp_current_db_version < 10360 )
+	if ( $wp_current_db_version < 11200 )
 		upgrade_280();
 
 	maybe_disable_automattic_widgets();
@@ -980,6 +980,9 @@
 
 	if ( $wp_current_db_version < 10360 )
 		populate_roles_280();
+	
+	if ( $wp_current_db_version < 11200 )
+		fix_attachment_slug_conflicts();
 }
 
 
Index: wp-admin/includes/schema.php
===================================================================
--- wp-admin/includes/schema.php	(revision 11201)
+++ wp-admin/includes/schema.php	(working copy)
@@ -576,4 +576,28 @@
 	}
 }
 
-?>
+/**
+ * Fix duplicate slugs in hierarchical data
+ * See http://core.trac.wordpress.org/ticket/9539
+ *
+ * @since 2.8.0
+ **/
+
+function fix_attachment_slug_conflicts() {
+	global $wpdb;
+	
+	$attachments = $wpdb->get_results("
+		SELECT attachment.*
+		FROM $wpdb->posts as attachment
+		JOIN $wpdb->posts as page
+		ON attachment.post_name = page.post_name
+		WHERE attachment.post_type = 'attachment'
+		AND page.post_type = 'page'
+		AND attachment.post_parent = page.post_parent
+		AND attachment.post_name <> ''
+		");
+	
+	while ( $attachment = array_pop($attachments) )
+		wp_update_post($attachment);
+} # fix_attachment_slug_conflicts()
+?>
\ No newline at end of file
