WordPress.org

Make WordPress Core

Opened 3 weeks ago

Last modified 11 days ago

#53668 new defect (bug)

Generated images for one file can be overwritten by another with the same name when mapping mime types for generated images

Reported by: ianmjones Owned by:
Milestone: 5.8.1 Priority: normal
Severity: normal Version: 5.8
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:

Description

When two images with same base file name but different extensions are added to the Media Library within the same month and both have thumbnails changed to same format by the image_editor_output_format filter, their thumbnails are perpetually confused!

Steps to reproduce:

  1. Add following filter to site that converts thumbnails to WebP for both jpeg and png source files.
add_filter( 'image_editor_output_format', function( $formats ) {
    $formats['image/jpeg'] = 'image/webp';
    $formats['image/png'] = 'image/webp';

    return $formats;
} );
  1. Add "picture.jpg" and "picture.png" to Media Library within a month.
  2. Notice that thumbnails for second upload clobber thumbnails of first, e.g. "picture-150x150.webp" shared by both images.
  3. "Permanently delete" one of the images from the Media Library and all intersecting thumbnails used by the other Media Library item will disappear.

See attached screenshots for example.

I think wp_unique_filename needs to take into account all thumbnails that are to be generated for the new upload.

Attachments (5)

Screenshot from 2021-07-15 14-52-04@2x.png (239.0 KB) - added by ianmjones 3 weeks ago.
Original files.
Screenshot from 2021-07-15 14-49-53@2x.png (228.2 KB) - added by ianmjones 3 weeks ago.
On upload thumbnails confused already.
Screenshot from 2021-07-15 14-55-24@2x.png (212.0 KB) - added by ianmjones 3 weeks ago.
Confused further in Media Library.
Screenshot from 2021-07-15 14-54-06@2x.png (352.3 KB) - added by ianmjones 3 weeks ago.
Files on disk.
53668.diff (3.7 KB) - added by ianmjones 3 weeks ago.
Patch that allows wp_unique_filename to take into consideration alternate formats for the uploaded image, as well as other upload formats that may result in thumbnails for the current image format.

Download all attachments as: .zip

Change History (14)

@ianmjones
3 weeks ago

On upload thumbnails confused already.

@ianmjones
3 weeks ago

Confused further in Media Library.

#1 @desrosj
3 weeks ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.8.1

Related #42437, #53667.

#2 @desrosj
3 weeks ago

This is closely related to #53667 in that this is an edge case with using the new image_editor_output_format filter. I've updated #53667 with a patch and status update, but copying here for visibility.

In the media chat, these were the steps agreed upon for 5.8 to address this issue and #53668:

  • Leave the filters in as is.
  • Update the inline docs for the filter to explain that it is a bit experimental, and there are two known potential issues when using the filter to change image formats for sub sizes.
  • Post a developer note detailing these two edge cases.
  • Follow up in 5.8.x releases to fix these edge cases.

53667.diff is an adjustment to the filter's inline documentation to make developer's aware of these two edge cases, and that the filter should generally be considered experimental.

#3 @desrosj
3 weeks ago

In 51442:

Media: Document edge cases with the new image_editor_output_format filter.

More testing has revealed that the image_editor_output_format filter has some interesting edge cases that developers should be aware of when electing to use this filter (see #53667 and #53668).

Because this is a new filter that was intended to be used for experimenting with different ways to handle generating image sizes and has not yet been adopted in the wild, expanding the inline documentation is an acceptable temporary solution while these edge cases are explored further and addressed.

Props mikeschroder, antpb, desrosj, adamsilverstein, ianmjones.
See #5366, #53668, #35725.

#4 @desrosj
3 weeks ago

In 51444:

Media: Document edge cases with the new image_editor_output_format filter.

More testing has revealed that the image_editor_output_format filter has some interesting edge cases that developers should be aware of when electing to use this filter (see #53667 and #53668).

Because this is a new filter that was intended to be used for experimenting with different ways to handle generating image sizes and has not yet been adopted in the wild, expanding the inline documentation is an acceptable temporary solution while these edge cases are explored further and addressed.

Props mikeschroder, antpb, desrosj, adamsilverstein, ianmjones.
Merges [51442] to the 5.8 branch.
See #53667, #53668, #35725.

@ianmjones
3 weeks ago

Patch that allows wp_unique_filename to take into consideration alternate formats for the uploaded image, as well as other upload formats that may result in thumbnails for the current image format.

#5 @ianmjones
3 weeks ago

  • Keywords has-patch needs-testing added; needs-patch removed

I've had a go at fixing this issue I raised, feels like the polite thing to do. ;-)

This ticket was mentioned in Slack in #core-media by ianmjones. View the logs.


3 weeks ago

#7 @desrosj
3 weeks ago

  • Summary changed from Thumbnails clobbered as results of image_editor_output_format filter not factored into wp_unique_filename to Generated images for one file can be overwritten by another with the same name when mapping mime types for generated images

This ticket was mentioned in Slack in #core-media by azaozz. View the logs.


3 weeks ago

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


11 days ago

Note: See TracTickets for help on using tickets.