[wp-trac] [WordPress Trac] #43816: Editing Image Can Lead to Mixed Metadata

WordPress Trac noreply at wordpress.org
Fri Apr 20 00:04:30 UTC 2018


#43816: Editing Image Can Lead to Mixed Metadata
--------------------------+-----------------------------
 Reporter:  rogerlos      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  4.9.5
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 == Summary
 If an image is uploaded at a size allowing the creation of a defined image
 size (ie, "large", "twentyseventeen-featured-image", etc.) and the image
 is then edited to a size which doesn't allow that defined size to be
 created, the non-supported size can still be placed and will display the
 original image.

 == Steps to Reproduce
 1. Upload an image which is slightly larger than a defined image size in a
 particular theme (for example, if using the WordPress default definition
 for "large" images, 1,024 pixels, upload an image 1,100 pixels wide)
 1. Edit the image, and scale or crop it to be 1,000 pixels wide
 1. Save edit
 1. Within the post editor, "add media", select the "large" image size, and
 place within body of post

 === Expected Behavior
 * //Developer//: The "large" image should not be able to be selected
 within the "Place Media" dialog
 * //Regular user//: The "large" image placed should reflect the image edit

 === Result
 The "large" size is selectable and the **original** image is placed within
 the page.

 === Other Effects
 In this particular example, if the Media Library is in "grid" view, and
 our edited image is selected, the dialog which opens will display the
 incorrect original image, as the dialog preferentially uses the "large"
 image size.

 == Source of Behavior

 I believe the problem stems from line 880 of
 https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-admin/includes
 /image-edit.php :

 {{{
 $meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes
 ) );
 }}}

 * `$meta['sizes']` contains all of the sizes which were able to be created
 when the image was uploaded
 * The return from `$img->multi_resize()` only has keys set for those sizes
 that can be created from the edited image
 * Using `array_merge` keeps the original values not returned by
 `$img->multi_resize()`, despite the fact they are no longer valid for this
 edit

 == Fix

 I believe the fix may be as simple as simply returning the result of
 `$img->multi_resize()` without merging it into the existing
 `$meta['sizes']`, which are mainly used in this context to create the
 `_wp_attachment_backup_sizes` array.

 {{{
 $meta['sizes'] = $img->multi_resize( $_sizes );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43816>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list