[wp-trac] [WordPress Trac] #42437: Thumbnails can overwrite other uploads if filename matches
WordPress Trac
noreply at wordpress.org
Wed Dec 4 20:36:39 UTC 2019
#42437: Thumbnails can overwrite other uploads if filename matches
--------------------------+-----------------------
Reporter: Viper007Bond | Owner: pbiron
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 5.3.1
Component: Upload | Version: 4.8.3
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+-----------------------
Comment (by azaozz):
Replying to [comment:35 pbiron]:
Thanks for the updated patch. It looks quite better but still needs some
considerations. Working on it now :)
> The revised patch:
>
> 1. Adds a number to any file that could cause a collision with sub-
sizes.
> 2. Then, it does the same collision detection that has always existed.
> 3. An finally, it checks collisions with existing files (e.g., sub-size
files uploaded before the patch was applied). That last check addresses
[https://core.trac.wordpress.org/ticket/42437#comment:18 @blobfolio]'s
comment.
Sounds good. I'm still a bit unsure about 1, but it seems like a good
"preventive" mechanism. It means that when an image like `picture-
scaled.jpg` is uploaded, it will be renamed to `picture-scaled-1.jpg`.
Then when generating the sub-sizes there will be `picture-
scaled-1-scaled.jpg`, `picture-scaled-1-300x200.jpg`, `picture-
scaled-1-1024x768.jpg`, etc.
Also perhaps replace uses of `array_filter()` with a callback with a
simple `foreach`? The difference is `array_filter()` will run through the
whole array no matter what, then return the filtered array. A callback can
return as soon as a match is found. Will try to test this with different
array lengths to see which is better/faster.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42437#comment:36>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list