[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
Tue Aug 17 20:18:59 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:26 ianmjones]:
> Replying to [comment:25 azaozz]:
> > For example: existing files like img.jpg, img-1.png, img-2.webp,
img-3.png and converting PNG and JPEG to WebP, and uploading img.jpg
again. Then the sub-sizes of img-3.png will be overwritten if the alt name
with .png extension is checked before the alt name with .webp (I'll try to
make another test for this edge case).
>
> As mentioned in your PR, I don't think my patch has the problem you
mention here with regards to skipped png version, recursion saves the day!
😉️
The logic there is that for each increase of `$number` all possible
filenames have to be checked. Doing that with recursion means it has to
"re-start" each time a possible name clash is detected.
Then if the conversion settings are like:
{{{
Array(
'image/png' => 'image/webp',
'image/jpeg' => 'image/webp',
'image/gif' => 'image/webp',
)
}}}
it will have to check 4 name variations for each `$number` increase. This
potentially can result in running `wp_unique_filename()` including the two
filters and `scandir()` 10-15 times. It's definitely going to be quite
slow :)
Also firing `wp_unique_filename` filter 10-15 times mostly for filenames
that will never be used seems like a regression. Perhaps we can pass the
alt filenames as another argument there, or maybe only the expected
filename after the image conversion.
> I see your point about the code you mentioned though. If uploading a new
series of photos (pic-1.png, pic-2.png, pic-3.png) and the second
"pic-2.png" clashes with "pic-2.jpg", what do you do?
>
> a) pic-1.png, pic-2-1.png, pic-3.png
> b) pic-1.png, pic-3.png, pic-4.png
>
> I take it (a) is expected?
Yep, as `pic-2` is the original name that WP shouldn't change.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53668#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list