Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 23022)
+++ wp-includes/media.php	(working copy)
@@ -252,7 +252,7 @@
  * @return array First item is the width, the second item is the height.
  */
 function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
-	if ( !$max_width and !$max_height )
+	if ( ( !$max_width and !$max_height ) || ( $max_width == $current_width && $max_height == $current_height ) )
 		return array( $current_width, $current_height );
 
 	$width_ratio = $height_ratio = 1.0;
@@ -1369,11 +1369,21 @@
 
 				// Nothing from the filter, so consult image metadata if we have it.
 				$size_meta = $meta['sizes'][ $size ];
+
+				// We have the actual image size, but might need to further constrain it if content_width is narrower
+				// This is not necessary for thumbnails and medium size
+				if ( 'thumbnail' == $size || 'medium' == $size ) {
+					$width = $size_meta['width'];
+					$height = $size_meta['height'];
+				}
+				else
+					list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size );
+
 				$sizes[ $size ] = array(
-					'height'      => $size_meta['height'],
-					'width'       => $size_meta['width'],
+					'height'      => $height,
+					'width'       => $width,
 					'url'         => $base_url . $size_meta['file'],
-					'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape',
+					'orientation' => $height > $width ? 'portrait' : 'landscape',
 				);
 			}
 		}
