Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against PHP 8.0.0 and higher versions: count() throwing fatal error on invalid countable types passed to the value parameter #5407

Closed
4 tasks
alfonso100 opened this issue Sep 8, 2022 · 0 comments · Fixed by #5411
Assignees
Labels
module: preload priority: high Issues which should be resolved as quickly as possible severity: critical Defect that prevents the testing/use of the software type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@alfonso100
Copy link
Contributor

Before submitting an issue please check that you’ve completed the following steps:
yes - Made sure you’re on the latest version
yes - Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug
A fatal error happens on WP 6.0.2 / PHP 8.1.9 / WPR 3.12.0.5 if the $_GET value is null here:

if ( 0 < count( $_GET ) || ( $this->query->is_pending( $url ) && $this->options->get( 'do_caching_mobile_files', false ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended

Per @engahmeds3ed :

According to PHP documentation
8.0.0 count() will now throw TypeError on invalid countable types passed to the value parameter.

this is the error:

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type
Countable|array, null given in /home/httpd/vhosts/site.com/httpdocs/wpcontent/plugins/wp-rocket/inc/Engine/Preload/Subscriber.php:188 Stack trace: #0
/home/httpd/vhosts/site.com/httpdocs/wp-content/plugins/wprocket/inc/Engine/Preload/Subscriber.php(188): count(NULL) #1
/home/httpd/vhosts/site.com/httpdocs/wp-includes/class-wp-hook.php(307):
WP_Rocket\Engine\Preload\Subscriber->update_cache_row('') #2
/home/httpd/vhosts/site.com/httpdocs/wp-includes/class-wp-hook.php(331): WP_Hook-
>apply_filters('', Array) #3 /home/httpd/vhosts/site.com/httpdocs/wpincludes/plugin.php(476): WP_Hook->do_action(Array) #4
/home/httpd/vhosts/site.com/httpdocs/wp-content/plugins/wprocket/inc/Engine/Optimization/Buffer/Optimization.php(109): do_action('rocket_after_pr...')
#5 [internal function]: WP_Rocket\Engine\Optimization\Buffer\Optimization-
>maybe_process_buffer('...', 9) #6 /home/httpd/vhosts/site.com/httpdocs/wpincludes/functions.php(5275): ob_end_flush() #7
/home/httpd/vhosts/site.com/httpdocs/wp-includes/class-wp-hook.php(307):
wp_ob_end_flush_all('') #8 /home/httpd/vhosts/site.com/httpdocs/wp-includes/class-wphook.php(331): WP_Hook->apply_filters('', Array) #9
/home/httpd/vhosts/site.com/httpdocs/wp-includes/plugin.php(476): WP_Hook-
>do_action(Array) #10 /home/httpd/vhosts/site.com/httpdocs/wp-includes/load.php(1102):
do_action('shutdown') #11 [internal function]: shutdown_action_hook() #12 {main} thrown in
/home/httpd/vhosts/site.com/httpdocs/wp-content/plugins/wprocket/inc/Engine/Preload/Subscriber.php on line 188

To Reproduce
Steps to reproduce the behavior:

  1. Empty/unset the $_GET parameter
  2. Trigger preload
  3. See error

Expected behavior
We should guard against this error.

Additional context
Tickets:
https://secure.helpscout.net/conversation/1997531112/365760?folderId=377611
https://secure.helpscout.net/conversation/2003166039/367167?folderId=273766

Slack thread:
https://wp-media.slack.com/archives/C43T1AYMQ/p1662646309671649

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior priority: high Issues which should be resolved as quickly as possible needs: grooming severity: critical Defect that prevents the testing/use of the software module: preload labels Sep 8, 2022
@piotrbak piotrbak added this to the 3.12.1 milestone Sep 8, 2022
@jeawhanlee jeawhanlee self-assigned this Sep 9, 2022
@Tabrisrp Tabrisrp mentioned this issue Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: preload priority: high Issues which should be resolved as quickly as possible severity: critical Defect that prevents the testing/use of the software type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants