Index: src/wp-admin/includes/image.php
===================================================================
--- src/wp-admin/includes/image.php	(revision 40076)
+++ src/wp-admin/includes/image.php	(working copy)
@@ -251,7 +251,28 @@
 			$editor = wp_get_image_editor( $file );
 
 			if ( ! is_wp_error( $editor ) ) { // No support for this type of file
-				$uploaded = $editor->save( $file, 'image/jpeg' );
+				/*
+				 * PDFs may have the same file filename as JPGs.
+				 * Use a random string for the PDF preview image to prevent the original JPG from being overwritten.
+				 */
+				$suffix = time() . rand( 100, 999 );
+				$dirname = pathinfo( $file, PATHINFO_DIRNAME );
+				$filename = pathinfo( $file, PATHINFO_FILENAME );
+
+				while ( true ) {
+					$new_filename = "{$filename}-{$suffix}-pdf";
+					$preview_file = "{$new_filename}.jpg";
+					$new_path = "{$dirname}/$preview_file";
+
+					if ( file_exists( $new_path ) ) {
+						$suffix++;
+					} else {
+						$filename = $new_path;
+						break;
+					}
+				}
+
+				$uploaded = $editor->save( $filename, 'image/jpeg' );
 				unset( $editor );
 
 				// Resize based on the full size image, rather than the source.
Index: tests/phpunit/tests/image/functions.php
===================================================================
--- tests/phpunit/tests/image/functions.php	(revision 40076)
+++ tests/phpunit/tests/image/functions.php	(working copy)
@@ -400,7 +400,14 @@
 		);
 
 		$metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
-		$this->assertSame( $expected, $metadata );
+		$this->assertArrayHasKey( 'sizes', $metadata, 'attachment should have size data' );
+		$this->assertEquals( count( $expected['sizes'] ), count( $metadata['sizes'] ) );
+
+		$this->assertContains( '-pdf', $metadata['sizes']['medium']['file'] );
+		$this->assertEquals( $expected['sizes']['medium']['height'], $metadata['sizes']['medium']['height'] );
+
+		$this->assertContains( '-pdf', $metadata['sizes']['large']['file'] );
+		$this->assertEquals( $expected['sizes']['large']['width'], $metadata['sizes']['large']['width'] );
 
 		unlink( $test_file );
 	}
@@ -435,7 +442,8 @@
 
 		$metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
 		$this->assertTrue( isset( $metadata['sizes']['test-size'] ), 'The `test-size` was not added to the metadata.' );
-		$this->assertSame( $metadata['sizes']['test-size'], $expected );
+		$this->assertContains( '-pdf', $metadata['sizes']['test-size']['file'] );
+		$this->assertEquals( $expected['height'], $metadata['sizes']['test-size']['height'] );
 
 		remove_image_size( 'test-size' );
 		remove_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10 );
