[wp-trac] [WordPress Trac] #24688: Memory exhaustion caused by very many unattached media

WordPress Trac noreply at wordpress.org
Mon Oct 8 09:35:20 UTC 2018

#24688: Memory exhaustion caused by very many unattached media
 Reporter:  andy                     |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Media                    |     Version:  2.5
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:

Comment (by david.binda):

 > My objection above still stands, to $where without parentheses in return
 "$where AND ...

 @kitchin , do you happen to have an example of code which would break by
 applying the patch the way it's being proposed here?

 My understanding is that the WHERE clause in `WP_Query::get_posts` where
 `posts_where` filter is being applied is being built as a chain of `AND`
 clauses. In case a plugin would be filtering `posts_where` while adding
 `OR` w/o proper parentheses, it would either have to be doing some weird
 string modifications (as the `$where` passed to the callback starts with `
 AND`, eg.: ` AND wptests_posts.post_parent = 85  AND
 (wptests_posts.post_mime_type LIKE 'image/%')  AND wptests_posts.post_type
 = 'attachment' AND ((wptests_posts.post_status = 'inherit'))` and is being
 appended to `... WHERE 1=1 ` string, eg.: `SELECT   wptests_posts.ID FROM
 wptests_posts  WHERE 1=1 `), or would be appending `OR` to the end of a
 string of `AND`s effectively bypassing all the previous conditions.

 That said, I don't think the callback proposed here should really wrap the
 initial part of the `$where` into parenthesis, especially as it would
 require us replacing the leading ` AND` by ` AND (` which really feels
 wrong and error prone. In case something would get wrong by not using
 parenthesis there, it would be because some plugin code does it wrong.

Ticket URL: <https://core.trac.wordpress.org/ticket/24688#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list