[wp-trac] [WordPress Trac] #46565: Mixed engine in tables, could bring to major WP failure! Also there is a small fix that could avoid that.

WordPress Trac noreply at wordpress.org
Tue Mar 19 18:49:44 UTC 2019


#46565: Mixed engine in tables, could bring to major WP failure! Also there is a
small fix that could avoid that.
------------------------------+-----------------------------
 Reporter:  Nokao             |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  General           |    Version:  4.9.8
 Severity:  normal            |   Keywords:  needs-patch
  Focuses:  coding-standards  |
------------------------------+-----------------------------
 ''First of all ... after MySQL decided to make InnoDB the default engine
 ... many of us have mixed database with both InnoDB and MyisAM labeled
 tables.

 If a plugin add a new table now (it happened to us with both WPML and
 Woocommerce) the new table will be mostly InnoDB but old table could be
 MyIsAM.

 That can bring to JOIN failures, that in our case made us lost primary key
 or foreign key links, but will definitely cause also tables **permanent
 locks** (due to plugin/software crash), and that took finally to the main
 problem:
 **data (rows) inserted with ID = 0**

 THAT alone should be advertised a lot around plugin developers, that
 should check if their plugin tables are equal to the current-default-
 engine and if they are not, they should:
 "alter TABLENAME engine = current-default-engine".''

 **Straight to the point:**
 Data with ID = 0 actually can make crash WordPress because of this:
 wp-includes/post.php:4867

 Please note that this code will make WordPress go into a recursive
 infinite loop (causing "fatal error memory exhausted") if the ID = 0.
 I know that ID = 0 is an abnormal situation, but believe me, if having
 locked tables makes this happen, you want to add a handbreak to that.

 **This is a small fix, but you surely can do better:**


 {{{
         // Start the search by looking at immediate children.
         if ( isset( $children[ $page_id ] ) ) {
                 // Always start at the end of the stack in order to
 preserve original `$pages` order.
                 $to_look = array_reverse( $children[ $page_id ] );

                 while ( $to_look ) {
                         $p = array_pop( $to_look );
                         if (!array_key_exists($p->ID,$pidx)) {
                                 $pidx[$p->ID]=true;
                                 $page_list[] = $p;
                                 if ( isset( $children[ $p->ID ] ) ) {
                                         foreach ( array_reverse(
 $children[ $p->ID ] ) as $child ) {
                                                 // Append to the
 `$to_look` stack to descend the tree.
                                                 $to_look[] = $child;
                                         }
                                 }
                         }
                 }
         }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46565>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list