Skip to content

Commit c4532c8

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 09614f4 + d1a313e commit c4532c8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/calendar/jewish.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,31 @@ static void MoladOfMetonicCycle(
429429
zend_long *pMoladHalakim)
430430
{
431431
register zend_ulong r1, r2, d1, d2;
432+
zend_long chk;
432433

433434
/* Start with the time of the first molad after creation. */
434435
r1 = NEW_MOON_OF_CREATION;
436+
chk = (zend_long)metonicCycle;
437+
438+
if (chk > (ZEND_LONG_MAX - NEW_MOON_OF_CREATION) / (HALAKIM_PER_METONIC_CYCLE & 0xFFFF)) {
439+
*pMoladDay = 0;
440+
*pMoladHalakim = 0;
441+
return;
442+
}
435443

436444
/* Calculate metonicCycle * HALAKIM_PER_METONIC_CYCLE. The upper 32
437445
* bits of the result will be in r2 and the lower 16 bits will be
438446
* in r1. */
439-
r1 += metonicCycle * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF);
447+
r1 += chk * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF);
448+
449+
if (chk > (ZEND_LONG_MAX - (r1 >> 16)) / ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF)) {
450+
*pMoladDay = 0;
451+
*pMoladHalakim = 0;
452+
return;
453+
}
454+
440455
r2 = r1 >> 16;
441-
r2 += metonicCycle * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF);
456+
r2 += chk * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF);
442457

443458
/* Calculate r2r1 / HALAKIM_PER_DAY. The remainder will be in r1, the
444459
* upper 16 bits of the quotient will be in d2 and the lower 16 bits

ext/calendar/tests/gh16234.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-16234 jewishtojd overflow on year argument
3+
--EXTENSIONS--
4+
calendar
5+
--FILE--
6+
<?php
7+
jewishtojd(1218182888, 1, 1218182888);
8+
echo "DONE";
9+
?>
10+
--EXPECT--
11+
DONE

0 commit comments

Comments
 (0)