Skip to content

Commit 5da4fea

Browse files
committed
Fix GH-16235 jdtogregorian overflow
1 parent 3d80d98 commit 5da4fea

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/calendar/gregor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ void SdnToGregorian(
153153
}
154154
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
155155

156+
if (temp < 0 || (temp / DAYS_PER_400_YEARS) > INT_MAX) {
157+
goto fail;
158+
}
159+
156160
/* Calculate the century (year/100). */
157161
century = temp / DAYS_PER_400_YEARS;
158162

ext/calendar/tests/gh16235.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-16235 (jdtogregorian overflow on argument)
3+
--EXTENSIONS--
4+
calendar
5+
--SKIPIF--
6+
<? if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
7+
--FILE--
8+
<?php
9+
jdtogregorian(92233658792494800);
10+
echo "DONE";
11+
?>
12+
--EXPECT--
13+
DONE

0 commit comments

Comments
 (0)