[wp-trac] [WordPress Trac] #53773: /wp-admin/includes/ajax-actions.php file line 3006 is creating divide by zero error
WordPress Trac
noreply at wordpress.org
Sat Jul 24 16:38:22 UTC 2021
#53773: /wp-admin/includes/ajax-actions.php file line 3006 is creating divide by
zero error
----------------------------------------+---------------------
Reporter: 2linctools | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.8.1
Component: Media | Version: 5.8
Severity: normal | Resolution:
Keywords: needs-patch good-first-bug | Focuses:
----------------------------------------+---------------------
Changes (by SergeyBiryukov):
* keywords: => needs-patch good-first-bug
* component: General => Media
* milestone: Awaiting Review => 5.8.1
Old description:
> In the /wp-admin/includes/ajax-actions.php file line 3006 it keeps
> popping up an error in our php error log that says it is trying to divide
> by zero. It produces an error over and over again.
>
> PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on
> line 3006
>
> This is line 3006:
> $max_pages = ceil( $total_posts / (int)
> $attachments_query->query['posts_per_page'] );
>
> Here is the whole section:
> /**
> * Filters the arguments passed to WP_Query during an Ajax
> * call for querying attachments.
> *
> * @since 3.7.0
> *
> * @see WP_Query::parse_query()
> *
> * @param array $query An array of query variables.
> */
> $query = apply_filters(
> 'ajax_query_attachments_args', $query );
> $attachments_query = new WP_Query( $query );
>
> $posts = array_map( 'wp_prepare_attachment_for_js',
> $attachments_query->posts );
> $posts = array_filter( $posts );
> $total_posts = $attachments_query->found_posts;
>
> if ( $total_posts < 1 ) {
> // Out-of-bounds, run the query again without LIMIT for
> total count.
> unset( $query['paged'] );
>
> $count_query = new WP_Query();
> $count_query->query( $query );
> $total_posts = $count_query->found_posts;
> }
>
> $max_pages = ceil( $total_posts / (int)
> $attachments_query->query['posts_per_page'] );
>
> header( 'X-WP-Total: ' . (int) $total_posts );
> header( 'X-WP-TotalPages: ' . (int) $max_pages );
>
> wp_send_json_success( $posts );
> }
>
> Our php error log looks like this: (truncated a lot)
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:46:05 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:46:14 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:46:32 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:46:34 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:58:34 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 18:58:42 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 19:35:22 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 19:35:58 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
> [23-Jul-2021 19:36:01 UTC] PHP Warning: Division by zero in /wp-
> admin/includes/ajax-actions.php on line 3006
New description:
In the /wp-admin/includes/ajax-actions.php file line 3006 it keeps popping
up an error in our php error log that says it is trying to divide by zero.
It produces an error over and over again.
{{{
PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on
line 3006
}}}
This is line 3006:
{{{
$max_pages = ceil( $total_posts / (int)
$attachments_query->query['posts_per_page'] );
}}}
Here is the whole section:
{{{
/**
* Filters the arguments passed to WP_Query during an Ajax
* call for querying attachments.
*
* @since 3.7.0
*
* @see WP_Query::parse_query()
*
* @param array $query An array of query variables.
*/
$query = apply_filters( 'ajax_query_attachments_args',
$query );
$attachments_query = new WP_Query( $query );
$posts = array_map( 'wp_prepare_attachment_for_js',
$attachments_query->posts );
$posts = array_filter( $posts );
$total_posts = $attachments_query->found_posts;
if ( $total_posts < 1 ) {
// Out-of-bounds, run the query again without LIMIT for
total count.
unset( $query['paged'] );
$count_query = new WP_Query();
$count_query->query( $query );
$total_posts = $count_query->found_posts;
}
$max_pages = ceil( $total_posts / (int)
$attachments_query->query['posts_per_page'] );
header( 'X-WP-Total: ' . (int) $total_posts );
header( 'X-WP-TotalPages: ' . (int) $max_pages );
wp_send_json_success( $posts );
}
}}}
Our php error log looks like this: (truncated a lot)
{{{
[23-Jul-2021 18:46:05 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 18:46:14 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 18:46:32 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 18:46:34 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 18:58:34 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 18:58:42 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 19:35:22 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 19:35:58 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
[23-Jul-2021 19:36:01 UTC] PHP Warning: Division by zero in /wp-
admin/includes/ajax-actions.php on line 3006
}}}
--
Comment:
Hi there, welcome to WordPress Trac! Thanks for the report.
Introduced in [51145].
It looks like a plugin or theme changes the `posts_per_page` value to `0`
using the `ajax_query_attachments_args` filter. By default, it's set to 40
in [source:tags/5.8/src/js/media/models/query.js?marks=174#L162 wp-
includes/js/media-models.js].
We should be able to check value and set `$max_pages` to `0` too in that
case.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53773#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list