Index: src/wp-includes/query.php
===================================================================
--- src/wp-includes/query.php
+++ src/wp-includes/query.php
@@ -4370,7 +4370,7 @@
 
 		$page = (array) $page;
 
-		if ( in_array( $page_obj->ID, $page ) ) {
+		if ( 0 !== $page_obj->ID && in_array( $page_obj->ID, $page ) ) {
 			return true;
 		} elseif ( in_array( $page_obj->post_title, $page ) ) {
 			return true;
Index: tests/phpunit/tests/query/conditionals.php
===================================================================
--- tests/phpunit/tests/query/conditionals.php
+++ tests/phpunit/tests/query/conditionals.php
@@ -809,4 +809,23 @@
 		$this->assertTrue( is_attachment( $post->post_title ) );
 		$this->assertTrue( is_attachment( $post->post_name ) );
 	}
+
+	function test_is_page_with_page_id_zero_and_random_page_slug() {
+		$post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
+		$this->go_to( "/?page_id=$post_id" );
+
+		// override post ID to 0 temporarily for testing
+		$_id = $GLOBALS['wp_query']->post->ID;
+		$GLOBALS['wp_query']->post->ID = 0;
+
+		$post = get_queried_object();
+		$q = $GLOBALS['wp_query'];
+
+		$this->assertTrue( $q->is_page() );
+		$this->assertFalse( $q->is_page( 'sample-page' ) );
+		$this->assertFalse( $q->is_page( 'random-page-slug' ) );
+
+		// revert $wp_query global change
+		$GLOBALS['wp_query']->post->ID = $_id;
+	}
 }
