[wp-trac] [WordPress Trac] #31767: insert_with_markers() is not atomic, leading to corrupted .htaccess updates under race conditions

WordPress Trac noreply at wordpress.org
Thu Mar 26 22:47:13 UTC 2015


#31767: insert_with_markers() is not atomic, leading to corrupted .htaccess updates
under race conditions
----------------------------+------------------------------
 Reporter:  tigertech       |       Owner:
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Filesystem API  |     Version:  4.1.1
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+------------------------------
Changes (by tigertech):

 * keywords:   => has-patch


Comment:

 The "misc.patch" file I uploaded solves this in most cases. It has two
 improvements:

 1) If there's an existing file and the target directory is writable, it
 saves it to a temporary file and then atomically renames it. This always
 avoids the corruption.

 2) If either of those conditions isn't true, it collects all the writes
 into one variable and then writes everything in a single fwrite, as soon
 as possible after the fopen. This minimizes the amount of the time that
 another process can see an incomplete file, and usually avoids the
 corruption.

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


More information about the wp-trac mailing list