Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php	(revision 35188)
+++ src/wp-includes/query.php	(working copy)
@@ -1833,11 +1833,25 @@
 		}
 
 		if ( '' != $qv['pagename'] ) {
-			$this->queried_object = get_page_by_path($qv['pagename']);
-			if ( !empty($this->queried_object) )
+			$this->queried_object = get_page_by_path( $qv['pagename'] );
+
+			if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
+				if ( preg_match( "/^[^%]*%(?:postname)%/", get_option( 'permalink_structure' ) ) ) {
+					// See if we also have a post with the same slug
+					$post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
+					if ( $post ) {
+						$this->queried_object = $post;
+						$this->is_page = false;
+						$this->is_single = true;
+					}
+				}
+			}
+
+			if ( ! empty( $this->queried_object ) ) {
 				$this->queried_object_id = (int) $this->queried_object->ID;
-			else
-				unset($this->queried_object);
+			} else {
+				unset( $this->queried_object );
+			}
 
 			if  ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) {
 				$this->is_page = false;
Index: tests/phpunit/tests/query/conditionals.php
===================================================================
--- tests/phpunit/tests/query/conditionals.php	(revision 35188)
+++ tests/phpunit/tests/query/conditionals.php	(working copy)
@@ -767,6 +767,32 @@
 		$this->assertFalse( $q->is_single( $p2 ) );
 	}
 
+	/**
+	 * @ticket 24612
+	 */
+	public function test_is_single_with_slug_that_clashes_with_attachment() {
+		$this->set_permalink_structure( '/%postname%/' );
+
+		$attachment_id = $this->factory->post->create( array(
+			'post_type'  => 'attachment',
+		) );
+
+		$post_id = $this->factory->post->create( array(
+			'post_title' => get_post( $attachment_id )->post_title
+		) );
+
+		$this->go_to( get_permalink( $post_id ) );
+
+		$q = $GLOBALS['wp_query'];
+
+		$this->assertTrue( $q->is_single() );
+		$this->assertTrue( $q->is_single( $post_id ) );
+		$this->assertFalse( $q->is_attachment() );
+		$this->assertFalse( $q->is_404() );
+
+		$this->set_permalink_structure();
+	}
+
 	function test_is_page() {
 		$post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
 		$this->go_to( "/?page_id=$post_id" );
