Skip to content

ext/date: Fix unbounded year loop in DateTimeZone::getTransitions() - #25465

Open
jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-gettransitions-far-future
Open

jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-gettransitions-far-future

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

After the last transition stored in tzdata (about 2037), timezone_transitions_get() computes transitions one year at a time. The loop always started at the year of the last stored transition. Years before $timestampBegin were computed and then discarded, so the cost depended on how far in the future the range was, not on its size.

(new DateTimeZone('Europe/Amsterdam'))->getTransitions(PHP_INT_MAX - 1, PHP_INT_MAX);

This call loops over about 292 billion years. That's hours of CPU, and it ends with "Maximum execution time exceeded". The bug has been present since PHP 8.1 (d9c8e5a, bug #80963).

The loop now starts at the year before the one containing $timestampBegin, or at the old starting year if that is later. The extra year matches timelib's own lookup in timelib_fetch_posix_timezone_offset(), which computes years Y−1 to Y+1. It covers a late-December change from the previous year that falls just inside the range in UTC.

The output is unchanged for every range: the years no longer computed only produced entries before $timestampBegin, which the existing check discarded. With the default $timestampBegin (PHP_INT_MIN), the starting year stays as before.

$end Year Before After
1e11 ~5,100 0.01 s 0.00 s
1e12 ~33,700 0.02 s 0.00 s
1e13 ~319,000 0.10 s 0.00 s
1e14 ~3.2 million 0.88 s 0.00 s
1e15 ~31.7 million 8.69 s 0.00 s
PHP_INT_MAX ~292 billion killed after hitting the 5 s limit (hours if unlimited) 0.00 s

@jorgsowa jorgsowa self-assigned this Nov 15, 2026
@jorgsowa
jorgsowa requested a review from derickr as a code owner November 15, 2026 12:50
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.

1 participant