Skip to content

ext/calendar: Fix integer overflow in GregorianToSdn() and JulianToJd()#22604

Open
arshidkv12 wants to merge 8 commits into
php:PHP-8.4from
arshidkv12:GregorianToSdn-2
Open

ext/calendar: Fix integer overflow in GregorianToSdn() and JulianToJd()#22604
arshidkv12 wants to merge 8 commits into
php:PHP-8.4from
arshidkv12:GregorianToSdn-2

Conversation

@arshidkv12

Copy link
Copy Markdown
Contributor

Comment thread ext/calendar/gregor.c Outdated
ext/calendar: Fix integer overflow in GregorianToSdn()

ext/calendar: Fix integer overflow in GregorianToSdn()

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mostly fine :)

Comment thread ext/calendar/gregor.c Outdated
ext/calendar: Fix integer overflow in GregorianToSdn()

ext/calendar: Fix integer overflow in GregorianToSdn()
Comment thread ext/calendar/gregor.c
@LamentXU123 LamentXU123 requested a review from devnexen July 6, 2026 08:15
Comment thread ext/calendar/tests/gh22602.phpt Outdated
calendar
--FILE--
<?php
var_dump(gregoriantojd(5, 5, PHP_INT_MAX > 2147483647 ? 2147483647 : PHP_INT_MAX));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we try the negative opposite case too ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok. I added the negative case too.

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like the juliantojd function has the exact same issue.

<?php
var_dump(juliantojd(5, 5, 2147483647));
?>
int(-784366681615)

Can you patch this in this PR as they share the exact same fix? Thank you!

@arshidkv12

Copy link
Copy Markdown
Contributor Author

Seems like the juliantojd function has the exact same issue.

<?php
var_dump(juliantojd(5, 5, 2147483647));
?>
int(-784366681615)

Can you patch this in this PR as they share the exact same fix? Thank you!

Ok

@LamentXU123 LamentXU123 changed the title ext/calendar: Fix integer overflow in GregorianToSdn() ext/calendar: Fix integer overflow in GregorianToSdn() and JulianToJd() Jul 6, 2026

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may also need a NEWS entry :)

Comment thread ext/calendar/gregor.c
Comment thread ext/calendar/tests/gh22602.phpt Outdated
@@ -0,0 +1,20 @@
--TEST--
Bug GH-22602: (gregoriantojd() integer overflow with INT_MAX year)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Bug GH-22602: (gregoriantojd() integer overflow with INT_MAX year)
Bug GH-22602: (gregoriantojd() and juliantojd() integer overflow with INT_MAX year)

ext/calendar: Fix integer overflow in GregorianToSdn()

ext/calendar: Fix integer overflow in GregorianToSdn()
@LamentXU123 LamentXU123 requested a review from devnexen July 6, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants