[wp-trac] [WordPress Trac] #52241: Infinite loop in clean_dirsize_cache()

WordPress Trac noreply at wordpress.org
Fri Oct 15 22:23:49 UTC 2021


#52241: Infinite loop in clean_dirsize_cache()
--------------------------------------------+-----------------------------
 Reporter:  raubvogel                       |       Owner:  hellofromTonya
     Type:  defect (bug)                    |      Status:  closed
 Priority:  normal                          |   Milestone:  5.9
Component:  Filesystem API                  |     Version:  5.6
 Severity:  major                           |  Resolution:  fixed
 Keywords:  has-patch early has-unit-tests  |     Focuses:  multisite
--------------------------------------------+-----------------------------
Changes (by hellofromTonya):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"51910" 51910]:
 {{{
 #!CommitTicketReference repository="" revision="51910"
 FileSystem API: Fix infinite loop on Windows for `clean_dirsize_cache()`.

 When the PHP native `dirname()` function is used on a Windows disk name -
 i.e. `C:\`-, it will return the same, i.e, it will return `C:\` again.

 The `clean_dirsize_cache()` function didn't have guard clause against
 this, which meant that on Windows based systems and IIS servers, this
 function would result in WordPress getting stuck into an infinite loop.

 The adjustment to the `while` part of the function fix this by checking if
 the return value of the `dirname()` function call is the same as the
 original path passed to `dirname()`, which effectively fixes the infinite
 loop.

 A number of other improvements made:

 1. Add input validation for the `$path` parameter to guard against invalid
 variable types being passed into the function.

 2. Guard against an empty `$path` parameter, which would result in an
 infinite loop on both Windows as well as *nix based systems.

 In both these cases, a PHP notice will now be thrown.

 3. When a non-empty string, which isn't a path would previously be passed,
 the `dirname()` function would transform that to a `.` and the `.` key in
 the transient cache would be cleared out.
 This was a bug as there is no relation between a non-path string and the
 root directory of file system.

 This bug has been fixed by checking that something could actually be a
 path and handling received non-empty, non-path input parameters in a
 special way, i.e only removing the cache key for the passed string and
 bowing out from further processing.

 Unfortunately, no tests can be added to guard against the infinite loop.

 For the other fixes, we have added appropriate unit tests.

 Follow-up up [49212], [49616], [49744].

 Props jrf, hellofromTonya, raubvogel, sergeybiryukov, codezen8, sjlevy,
 drosmog, teachlynx, ekojr, bartoszgrzesik, joegasper, janthiel,
 josephdickson, ocean90, audrasjb.
 Fixes #52241.
 }}}

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


More information about the wp-trac mailing list