Make WordPress Core

Opened 5 months ago

Last modified 4 weeks ago

#62342 reviewing defect (bug)

wpdb->get_table_from_query: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

Reported by: kkmuffme's profile kkmuffme Owned by: audrasjb's profile audrasjb
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch has-unit-tests early
Focuses: Cc:

Description

e.g. when calling set_transient( where the value is extremely long it will fail with a backtrack limit error

Additionally, the regex has an unnecessary "s" flag and is technically incorrect since it's not matching balanced tags

There are 2 options:

  • /\((?!\s*select)[^()]+\)/i which reduces backtracking by 65% and is also about 20% faster
  • /\((?!\s*select)(?:[^()]+|(?R))*+\)/i is the technically correct way to match - it's 30% less backtracking and on average as fast as before (slightly slower if no matches, slightly faster with matches)

Additionally, the preg_replace result needs to be validated - if it returns null, I'd suggest to retry it with the first, since it's possible it won't fail with a backtracking error.

Change History (7)

This ticket was mentioned in PR #7711 on WordPress/wordpress-develop by @kkmuffme.


5 months ago
#1

  • Keywords has-patch has-unit-tests added
  • Fix backtrack limit error 62342
  • Remove redundant "s" flag
  • make regex technically more correct

Trac ticket: https://core.trac.wordpress.org/ticket/62342

#2 @apermo
8 weeks ago

Hey @kkmuffme I ran into a similar issue via our sentry.

Mine throws Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

in https://core.trac.wordpress.org/browser/tags/6.7/src/wp-includes/class-wpdb.php#L3819

<?php
if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES)\s+(?:WHERE\s+Name\s+)?LIKE\s*("|\')((?:[\\\\0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)%?\\1/is', $query, $maybe ) ) {
        return str_replace( '\\_', '_', $maybe[2] );
}

In my case I can follow the trace down to a update_option() where it ultimately begins, so I think this is exactly the same issue as yours and should be covered by your PR.

#3 @audrasjb
8 weeks ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to audrasjb
  • Status changed from new to reviewing

Hello, thanks for the report and the PR,
Moving this to 6.8, pending detailed code review.

@shailu25 commented on PR #7711:


7 weeks ago
#4

@kkmuffme Could you please fix the suggested PHPCS issues?

@audrasjb commented on PR #7711:


7 weeks ago
#5

I fixed the WPCS issues.

#6 @audrasjb
6 weeks ago

  • Keywords early added

Adding early keyword as it touches the Database component. This should be committed by next week or punted to next release.

#7 @audrasjb
4 weeks ago

  • Milestone changed from 6.8 to 6.9

Moving to 6.9 as we're getting close to 6.8 beta 1.

Note: See TracTickets for help on using tickets.