Skip to content

Commit 03ae4a5

Browse files
committed
Fix phpGH-16234 jewishtojd overflow on year argument.
1 parent 3d80d98 commit 03ae4a5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ext/calendar/jewish.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,25 @@ static void MoladOfMetonicCycle(
433433
zend_long *pMoladHalakim)
434434
{
435435
register zend_ulong r1, r2, d1, d2;
436+
zend_long chk;
436437

437438
/* Start with the time of the first molad after creation. */
438439
r1 = NEW_MOON_OF_CREATION;
440+
chk = (zend_long)metonicCycle;
441+
442+
if (chk * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF) > ZEND_LONG_MAX ||
443+
chk * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF) > ZEND_LONG_MAX) {
444+
*pMoladDay = 0;
445+
*pMoladHalakim = 0;
446+
return;
447+
}
439448

440449
/* Calculate metonicCycle * HALAKIM_PER_METONIC_CYCLE. The upper 32
441450
* bits of the result will be in r2 and the lower 16 bits will be
442451
* in r1. */
443-
r1 += metonicCycle * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF);
452+
r1 += chk * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF);
444453
r2 = r1 >> 16;
445-
r2 += metonicCycle * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF);
454+
r2 += chk * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF);
446455

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

ext/calendar/tests/gh16234.phpt

+11
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)