Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 6372)
+++ wp-includes/query.php	(working copy)
@@ -841,6 +841,12 @@
 				$q['pagename'] = sanitize_title(basename($page_paths));
 				$q['name'] = $q['pagename'];
 				$where .= " AND (ID = '$reqpage')";
+				$reqpage_obj = get_page($reqpage);
+				if ( 'attachment' == $reqpage_obj->post_type ) {
+					$this->is_attachment = true;
+					$this->is_page = false;
+					$q['attachment_id'] = $reqpage;
+				}
 			}
 		} elseif ('' != $q['attachment']) {
 			$q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 6372)
+++ wp-includes/post.php	(working copy)
@@ -976,7 +976,7 @@
 	foreach($page_paths as $pathdir)
 		$full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
 
-	$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $leaf_path ));
+	$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'page' OR post_type = 'attachment')", $leaf_path ));
 
 	if ( empty($pages) )
 		return NULL;
