Skip to content

Commit

Permalink
Fix GH-16384: cal_from_jd overflow on julian_day argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Nov 17, 2024
1 parent fbb0061 commit 265797e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/calendar/gregor.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ void SdnToGregorian(
/* Calculate the century (year/100). */
century = temp / DAYS_PER_400_YEARS;

if (century > ((INT_MAX / 100) - (temp / DAYS_PER_4_YEARS))) {
goto fail;
}

/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
year = (century * 100) + (temp / DAYS_PER_4_YEARS);
Expand Down
29 changes: 29 additions & 0 deletions ext/calendar/tests/gh16834.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-16834 (cal_from_jd from julian_day argument)
--EXTENSIONS--
calendar
--FILE--
<?php
var_dump(cal_from_jd(076545676543223, CAL_GREGORIAN));
?>
--EXPECTF--
array(9) {
["date"]=>
string(5) "0/0/0"
["month"]=>
int(0)
["day"]=>
int(0)
["year"]=>
int(0)
["dow"]=>
int(%d)
["abbrevdayname"]=>
string(3) "%s"
["dayname"]=>
string(9) "%s"
["abbrevmonth"]=>
string(0) ""
["monthname"]=>
string(0) ""
}

0 comments on commit 265797e

Please sign in to comment.