Skip to content

Commit 265797e

Browse files
committed
Fix phpGH-16384: cal_from_jd overflow on julian_day argument.
1 parent fbb0061 commit 265797e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ext/calendar/gregor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ void SdnToGregorian(
160160
/* Calculate the century (year/100). */
161161
century = temp / DAYS_PER_400_YEARS;
162162

163+
if (century > ((INT_MAX / 100) - (temp / DAYS_PER_4_YEARS))) {
164+
goto fail;
165+
}
166+
163167
/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
164168
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
165169
year = (century * 100) + (temp / DAYS_PER_4_YEARS);

ext/calendar/tests/gh16834.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-16834 (cal_from_jd from julian_day argument)
3+
--EXTENSIONS--
4+
calendar
5+
--FILE--
6+
<?php
7+
var_dump(cal_from_jd(076545676543223, CAL_GREGORIAN));
8+
?>
9+
--EXPECTF--
10+
array(9) {
11+
["date"]=>
12+
string(5) "0/0/0"
13+
["month"]=>
14+
int(0)
15+
["day"]=>
16+
int(0)
17+
["year"]=>
18+
int(0)
19+
["dow"]=>
20+
int(%d)
21+
["abbrevdayname"]=>
22+
string(3) "%s"
23+
["dayname"]=>
24+
string(9) "%s"
25+
["abbrevmonth"]=>
26+
string(0) ""
27+
["monthname"]=>
28+
string(0) ""
29+
}

0 commit comments

Comments
 (0)