[wp-trac] [WordPress Trac] #64404: Uncaught DivisionByZeroError: Modulo by zero

WordPress Trac noreply at wordpress.org
Mon Feb 23 08:41:54 UTC 2026


#64404: Uncaught DivisionByZeroError: Modulo by zero
----------------------------+--------------------------
 Reporter:  kaushiksomaiya  |       Owner:  westonruter
     Type:  defect (bug)    |      Status:  accepted
 Priority:  normal          |   Milestone:  7.0
Component:  Cron API        |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+--------------------------

Comment (by vapvarun):

 Ran into this on trunk (9e4cb58243), PHP 8.2.29.

 Makes sense -- `0 === $interval` on line 447 is strict, so `false` gets
 past it and hits the modulo on 463.

 Tested PR #10619 -- it fixes the crash, but there's a failing test:

 {{{
 Tests_Cron::test_invalid_recurrence_for_event_returns_error
 sprintf(): Argument number must be greater than zero
 wp-includes/cron.php:428
 }}}

 One thought -- instead of `0 === $interval`, widen the check to catch
 `false`, `0`, and negative values:

 In `wp_reschedule_event()` around line 447:
 {{{#!php
 if ( ! is_numeric( $interval ) || $interval <= 0 ) {
     if ( $wp_error ) {
         if ( ! isset( $schedules[ $recurrence ] ) ) {
             return new WP_Error( 'invalid_schedule', __( 'Event schedule
 does not exist.' ) );
         }
         return new WP_Error( 'invalid_interval', __( 'Event schedule has
 an invalid interval.' ) );
     }
     return false;
 }
 }}}

 And in `wp_schedule_event()` around line 283, validate the interval before
 saving:
 {{{#!php
 $interval = $schedules[ $recurrence ]['interval'];
 if ( ! is_numeric( $interval ) || $interval <= 0 ) {
     if ( $wp_error ) {
         return new WP_Error( 'invalid_interval', __( 'Event schedule has
 an invalid interval.' ) );
     }
     return false;
 }
 }}}

 This way bad intervals get caught at schedule time too, not just on
 reschedule. Cron tests pass locally (75/75). Happy to open a PR if the
 approach looks right.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64404#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list