#44095 closed defect (bug) (duplicate)
wp_generate_attachment_metadata() can overwrite previously uploaded images with the intermediate sized images it creates
Reported by: | pbiron | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.1 |
Component: | Media | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
When wp_generate_attachment_metadata() creates/saves intermediate sized images, it can sometimes overwrite an original image from a previous upload.
Steps to reproduce:
- set thumbnail size to 150x150
- create a 300x300 image named
foo-150x150.jpg
- upload
foo-150x150.jpg
- create another 300x300 image named
foo.jpg
- 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:
- 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) - a photographer then uploads their photograph of a sunset named
sunset.jpg
...and the photographer has just overwritten the painter's original image :-(
Attachments (2)
Change History (9)
#1
@
6 years ago
- Summary changed from wp_generate_attachment_metadata() can overwrite previously uploaded images to wp_generate_attachment_metadata() can overwrite previously uploaded images with the intermediate sized images it creates
#2
@
6 years ago
- Keywords dev-feedback added
There are a number of places in the process where the intermediate sized filenames could be "unique"-ified, e.g.,
- WP_Image_Editor::generate_filename()
- WP_Image_Editor::get_output_format()
- WP_Image_Editor_GD::multi_resize() (and the equivalent in WP_Image_Editor_Imagick::multi_resize()).
I'm fairly unfamiliar with that part of the core code so I'm not really sure which of those place (and maybe others that I've discovered) would be the safest/most reliable for core's needs.
However, I will note that 2 very widely used plugins (Regenerate Thumbnails and WooCommerce) make calls to WP_Image_Editor::generate_filename()
but not WP_Image_Editor_{GD|Imagick}::multi_resize()
when they resize images.
So, I'm very interested in the opinion of those who are familiar with both the relevant parts of the core code and how other plugins would deal with any change.
#3
follow-up:
↓ 4
@
6 years ago
This is a known issue. If I could just find the original ticket right now...
#4
in reply to:
↑ 3
@
6 years ago
Replying to swissspidy:
This is a known issue. If I could just find the original ticket right now...
I looked to see if it was a known issue before opening this ticket and couldn't find anything.
#5
follow-up:
↓ 6
@
6 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
I think #42437 is the one. Feel free to reopen if this is something different.
example image to use in the "steps to reproduce"