diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index f26d611092db..bca065549e5c 100644 --- a/ext/calendar/calendar.c +++ b/ext/calendar/calendar.c @@ -41,7 +41,7 @@ enum cal_name_type_t { CAL_NUM_CALS }; -typedef zend_long (*cal_to_jd_func_t) (int month, int day, int year); +typedef zend_long (*cal_to_jd_func_t) (zend_long month, zend_long day, zend_long year); typedef void (*cal_from_jd_func_t) (zend_long jd, int *year, int *month, int *day); typedef char *(*cal_as_string_func_t) (int year, int month, int day); diff --git a/ext/calendar/french.c b/ext/calendar/french.c index 0707e27ed8d1..913098325629 100644 --- a/ext/calendar/french.c +++ b/ext/calendar/french.c @@ -115,9 +115,9 @@ void SdnToFrench( } zend_long FrenchToSdn( - int year, - int month, - int day) + zend_long year, + zend_long month, + zend_long day) { /* check for invalid dates */ if (year < 1 || year > 14 || diff --git a/ext/calendar/gregor.c b/ext/calendar/gregor.c index eaee9c8c73c7..4047051cf3e1 100644 --- a/ext/calendar/gregor.c +++ b/ext/calendar/gregor.c @@ -200,12 +200,12 @@ void SdnToGregorian( } zend_long GregorianToSdn( - int inputYear, - int inputMonth, - int inputDay) + zend_long inputYear, + zend_long inputMonth, + zend_long inputDay) { zend_long year; - int month; + zend_long month; /* check for invalid dates */ if (inputYear == 0 || inputYear < -4714 || diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c index b589c4cb2617..2e20698e4d96 100644 --- a/ext/calendar/jewish.c +++ b/ext/calendar/jewish.c @@ -531,13 +531,17 @@ static void FindTishriMolad( * and time of the starting molad. */ static void FindStartOfYear( - int year, + zend_long year, int *pMetonicCycle, int *pMetonicYear, zend_long *pMoladDay, zend_long *pMoladHalakim, int *pTishri1) { + /* JewishToSdn() rejects years outside this range, so the int outputs + * below cannot overflow. */ + ZEND_ASSERT(year > 0 && year < INT_MAX); + *pMetonicCycle = (year - 1) / 19; *pMetonicYear = (year - 1) % 19; MoladOfMetonicCycle(*pMetonicCycle, pMoladDay, pMoladHalakim); @@ -696,9 +700,9 @@ void SdnToJewish( * and compare with the original. */ zend_long JewishToSdn( - int year, - int month, - int day) + zend_long year, + zend_long month, + zend_long day) { zend_long sdn; int metonicCycle; diff --git a/ext/calendar/julian.c b/ext/calendar/julian.c index c24527941d3e..d539e2b45bd8 100644 --- a/ext/calendar/julian.c +++ b/ext/calendar/julian.c @@ -213,12 +213,12 @@ void SdnToJulian( } zend_long JulianToSdn( - int inputYear, - int inputMonth, - int inputDay) + zend_long inputYear, + zend_long inputMonth, + zend_long inputDay) { zend_long year; - int month; + zend_long month; /* check for invalid dates */ if (inputYear == 0 || inputYear < -4713 || diff --git a/ext/calendar/sdncal.h b/ext/calendar/sdncal.h index fa3aa7c641a9..17202791c439 100644 --- a/ext/calendar/sdncal.h +++ b/ext/calendar/sdncal.h @@ -69,17 +69,17 @@ /* Gregorian calendar conversions. */ void SdnToGregorian(zend_long sdn, int *pYear, int *pMonth, int *pDay); -zend_long GregorianToSdn(int year, int month, int day); +zend_long GregorianToSdn(zend_long year, zend_long month, zend_long day); extern const char * const MonthNameShort[13]; extern const char * const MonthNameLong[13]; /* Julian calendar conversions. */ void SdnToJulian(zend_long sdn, int *pYear, int *pMonth, int *pDay); -zend_long JulianToSdn(int year, int month, int day); +zend_long JulianToSdn(zend_long year, zend_long month, zend_long day); /* Jewish calendar conversions. */ void SdnToJewish(zend_long sdn, int *pYear, int *pMonth, int *pDay); -zend_long JewishToSdn(int year, int month, int day); +zend_long JewishToSdn(zend_long year, zend_long month, zend_long day); extern const char * const JewishMonthName[14]; extern const char * const JewishMonthNameLeap[14]; extern const char * const JewishMonthHebName[14]; @@ -88,7 +88,7 @@ extern const int monthsPerYear[19]; /* French republic calendar conversions. */ void SdnToFrench(zend_long sdn, int *pYear, int *pMonth, int *pDay); -zend_long FrenchToSdn(int inputYear, int inputMonth, int inputDay); +zend_long FrenchToSdn(zend_long inputYear, zend_long inputMonth, zend_long inputDay); extern const char * const FrenchMonthName[14]; /* Islamic calendar conversions. */ diff --git a/ext/calendar/tests/juliantojd_overflow.phpt b/ext/calendar/tests/juliantojd_overflow.phpt index cdf1b203d96c..ed03c4452940 100644 --- a/ext/calendar/tests/juliantojd_overflow.phpt +++ b/ext/calendar/tests/juliantojd_overflow.phpt @@ -6,7 +6,11 @@ calendar --FILE-- --EXPECT-- -622764916319 +784368370049 +0 diff --git a/ext/calendar/tests/tojd_narrowing.phpt b/ext/calendar/tests/tojd_narrowing.phpt new file mode 100644 index 000000000000..bc82c1a50d1e --- /dev/null +++ b/ext/calendar/tests/tojd_narrowing.phpt @@ -0,0 +1,44 @@ +--TEST-- +*tojd(): arguments outside the int range must not alias into the accepted range +--EXTENSIONS-- +calendar +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; + } +} +?> +--EXPECT-- +gregoriantojd +int(1721426) +int(0) +int(0) +int(0) +juliantojd +int(1721424) +int(0) +int(0) +int(0) +jewishtojd +int(347998) +int(0) +int(0) +ValueError: jewishtojd(): Argument #3 ($year) must be between -2147483648 and 2147483647 +frenchtojd +int(2375840) +int(0) +int(0) +int(0)