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: |
|
Owned by: |
|
---|---|---|---|
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
#2
@
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
@
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.
Trac ticket: https://core.trac.wordpress.org/ticket/62342