Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-16834: cal_from_jd overflow on julian_day argument. #16836

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this check be after the reassignment of temp? temp itself can't overflow I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true I missed that line.

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
31 changes: 31 additions & 0 deletions ext/calendar/tests/gh16834.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
GH-16834 (cal_from_jd from julian_day argument)
--EXTENSIONS--
calendar
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip for 64bit platforms only"); ?>
--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) ""
}
Loading