Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#61468 new defect (bug)

DivisionByZero issue for comments on PHP8.0+

Reported by: hideandgeek404's profile hideandgeek404 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version:
Component: Comments Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Quick summary

I have found an issue with PHP 8.0+ where if the comments_per_page option is set to 0, which really shouldn't be possible, PHP 8.0+ fires a DivisionByZero exception. This means that any blog post with the comments section and form showing then hits a fatal error.

Steps to reproduce

  1. Set the site's PHP version to 8.0+
  2. Visit Settings > Discussion and set the Break comments into pages with x option to 0.
  3. Save changes
  4. Visit a blog post with comments active
  5. See the blank post and fatal error in the logs

A clear and concise description of what you expected to happen.

The blog post should load and show any existing comments above the comment form.

What actually happened

When comments are activated on blog posts, loading the blog post in the front end causes a blank screen and a fatal error in the logs.

PHP Fatal error:  Uncaught DivisionByZeroError: Division by zero in /wordpress/core/6.5.4/wp-includes/comment-template.php:1520

In wp-includes/comment-template.php on line 1520 we find this code:

$comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1 ) * $per_page;

If the comments_per_page option is always going to be used for this math, it should not be possible to set it to zero in Settings > Discussion.

Change History (5)

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


5 months ago
#1

  • Keywords has-patch added

In my opinion it makes to sense to be able to set the minimum comments per page to zero, while having the pagination option enabled.

Trac ticket: #61468

#3 @narenin
5 months ago

  • Keywords dev-feedback added

Hi @hideandgeek404

In my opinion we can handle the case where $per_page is 0 by adding a check to ensure that it doesn't perform any division by zero or other invalid operations. I have added patch that can handle this scenario.

https://github.com/WordPress/wordpress-develop/pull/6863

Last edited 5 months ago by narenin (previous) (diff)

#4 @Presskopp
5 months ago

btw: I switched to PHP7 and the issue remained..

#5 @hellofromTonya
5 months ago

  • Version trunk deleted

Removing trunk as the Version that introduced this issue. Why? I'm not identifying any commits that happened during the current 6.6 or 6.7-alpha cycles. Once (or if) the commit is found, the Version should be updated.

Note: See TracTickets for help on using tickets.