[wp-trac] [WordPress Trac] #53668: Generated images for one file can be overwritten by another with the same name when mapping mime types for generated images

WordPress Trac noreply at wordpress.org
Fri Aug 13 23:23:45 UTC 2021


#53668: Generated images for one file can be overwritten by another with the same
name when mapping mime types for generated images
----------------------------------------------------+---------------------
 Reporter:  ianmjones                               |       Owner:  (none)
     Type:  defect (bug)                            |      Status:  new
 Priority:  normal                                  |   Milestone:  5.8.1
Component:  Media                                   |     Version:  5.8
 Severity:  normal                                  |  Resolution:
 Keywords:  has-patch needs-testing has-unit-tests  |     Focuses:
----------------------------------------------------+---------------------

Comment (by azaozz):

 Replying to [comment:20 ianmjones]:

 Yes the alt patch needs more work.

 Looking at `_wp_check_alternate_output_format_uniqueness()` again, seems
 it tries to account for "circular" use of the `image_editor_output_format`
 filter. For example:

 {{{
 Array(
     'image/png' => 'image/gif',
     'image/gif' => 'image/jpeg',
     'image/jpeg' => 'image/png'
 )
 }}}

 In that case uploaded PNG image will be converted to a GIF. There's no
 need to test for additional conversion settings. This is a weakness/lack
 of docs in the current filter implementation that needs fixing, the file
 naming shouldn't account for such cases.

 Then `_wp_check_alternate_output_format_uniqueness()` runs
 `wp_unique_filename()` in a loop after the original filename was made
 unique. However seems that loop will run only once as there's `static
 $checking_alternates;` which prevents calling `wp_unique_filename()`
 second time. That's okay, a loop doesn't seem needed. There can only be
 one conversion per uploaded image as explained above. In addition running
 all of wp_unique_filename() again seems not that efficient. That's why I
 started on an alt patch, to see if things can be simplified and more
 efficient :)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53668#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list