Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php	(revision 48280)
+++ src/wp-includes/media.php	(working copy)
@@ -1508,9 +1508,19 @@
  *                     or false if dimensions cannot be determined.
  */
 function wp_image_src_get_dimensions( $image_src, $image_meta ) {
-	$image_filename = wp_basename( $image_src );
+	// Ensure the $image_meta is for this image. For example the attachment ID used to get the meta
+	// may have changed if the site was exported and then imported, etc.
+	if ( ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) {
+		return false;
+	}
 
-	if ( wp_basename( $image_meta['file'] ) === $image_filename ) {
+	list( $image_src ) = explode( '?', $image_src );
+
+	// Match the relative image path inside the uploads directory plus the file name.
+	if (
+		strpos( $image_src, $image_meta['file'] ) !== false &&
+		preg_match( '|' . preg_quote( $image_meta['file'] ) . '$|', $image_src )
+	) {
 		return array(
 			(int) $image_meta['width'],
 			(int) $image_meta['height'],
@@ -1517,8 +1527,26 @@
 		);
 	}
 
+	if ( empty( $image_meta['sizes'] ) ) {
+		return false;
+	}
+
+	// Retrieve the uploads sub-directory from the full size image.
+	$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
+
+	if ( $dirname ) {
+		$dirname = trailingslashit( $dirname );
+	}
+
+	$src_filename = wp_basename( $image_src );
+
 	foreach ( $image_meta['sizes'] as $image_size_data ) {
-		if ( $image_filename === $image_size_data['file'] ) {
+		if (
+			// First check if the filename matches (cheap),
+			// then check if the filename and the relative upload directory is at the end of $image_src.
+			$src_filename === $image_size_data['file'] &&
+			preg_match( '|' . preg_quote( $dirname . $image_size_data['file'] ) . '$|', $image_src )
+		) {
 			return array(
 				(int) $image_size_data['width'],
 				(int) $image_size_data['height'],
