Index: src/wp-admin/includes/post.php
===================================================================
--- src/wp-admin/includes/post.php	(revision 34678)
+++ src/wp-admin/includes/post.php	(working copy)
@@ -1296,7 +1296,7 @@
 			$view_link = get_preview_post_link( $post, array(), $draft_link );
 			$preview_target = " target='wp-preview-{$post->ID}'";
 		} else {
-			if ( 'publish' === $post->post_status ) {
+			if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
 				$view_link = get_permalink( $post );
 			} else {
 				// Allow non-published (private, future) to be viewed at a pretty permalink.
@@ -1310,7 +1310,7 @@
 		$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
 
 		if ( false !== $view_link ) {
-			$return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $permalink . "</a>\n";
+			$return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $view_link . "</a>\n";
 		} else {
 			$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
 		}
Index: src/wp-includes/link-template.php
===================================================================
--- src/wp-includes/link-template.php	(revision 34678)
+++ src/wp-includes/link-template.php	(working copy)
@@ -386,6 +386,9 @@
 
 	$post = get_post( $post );
 	$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
+	if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) {
+		$parent = false;
+	}
 
 	if ( $wp_rewrite->using_permalinks() && $parent ) {
 		if ( 'page' == $parent->post_type )
@@ -403,6 +406,8 @@
 
 		if ( ! $leavename )
 			$link = str_replace( '%postname%', $name, $link );
+	} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
+		$link = home_url( user_trailingslashit( $post->post_name ) );
 	}
 
 	if ( ! $link )
Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 34678)
+++ src/wp-includes/query.php	(working copy)
@@ -3580,6 +3580,11 @@
 		// Check post status to determine if post should be displayed.
 		if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
 			$status = get_post_status($this->posts[0]);
+			if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) {
+				$this->is_page = false;
+				$this->is_single = true;
+				$this->is_attachment = true;
+			}
 			$post_status_obj = get_post_status_object($status);
 			//$type = get_post_type($this->posts[0]);
 
