Index: src/wp-includes/canonical.php
===================================================================
--- src/wp-includes/canonical.php	(revision 57099)
+++ src/wp-includes/canonical.php	(working copy)
@@ -548,9 +548,11 @@
 	$is_attachment_redirect = false;
 
 	if ( is_attachment() && ! get_option( 'wp_attachment_pages_enabled' ) ) {
-		$attachment_id = get_query_var( 'attachment_id' );
+		$attachment_id        = get_query_var( 'attachment_id' );
+		$attachment_post      = get_post( $attachment_id );
+		$attachment_parent_id = $attachment_post ? $attachment_post->post_parent : 0;
 
-		if ( current_user_can( 'read_post', $attachment_id ) ) {
+		if ( $attachment_parent_id && current_user_can( 'read_post', $attachment_parent_id ) ) {
 			$redirect_url = wp_get_attachment_url( $attachment_id );
 
 			$is_attachment_redirect = true;
