[wp-trac] [WordPress Trac] #44095: wp_generate_attachment_metadata() can overwrite previously uploaded images

WordPress Trac noreply at wordpress.org
Tue May 15 18:05:17 UTC 2018


#44095: wp_generate_attachment_metadata() can overwrite previously uploaded images
--------------------------+-----------------------------
 Reporter:  pbiron        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When
 [[https://developer.wordpress.org/reference/functions/wp_generate_attachment_metadata/|wp_generate_attachment_metadata()]]
 creates/saves intermediate sized images, it can sometimes overwrite an
 original image from a previous upload.

 Steps to reproduce:

 1. set thumbnail size to 150x150
 1. create a 300x300 image named `foo-150x150.jpg`
 1. upload `foo-150x150.jpg`
 1. create another 300x300 image named `foo.jpg`
 1. upload `foo.jpg`

 If you then check the appropriate dir in `/wp-content/uploads` you will
 see that the original `foo-150x150.jpg` has been overwritten by the
 `thumbnail`-sized version of `foo.jpg`.

 Original filenames containing `-{width}x{height}` suffixes can be quite
 common, especially on artwork-related sites.  A real-world example of the
 "steps to reproduce" above is as follows:

 1. a painter does an oil painting of a sunset on a 150cmx150cm canvas and
 uploads a photo of that artwork named `sunset-150x150.jpg` (where, in
 their mind, the `-150x150` suffix is the canvas size of their painting)
 1. a photographer then uploads their photograph of a sunset named
 `sunset.jpg`

 ...and the photographer has just overwritten the painter's original image
 :-(

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


More information about the wp-trac mailing list