Skip to content

integer overflow tm2unixtime.c:403:4 #17415

@chongwick

Description

@chongwick

Description

The following code:

<?php
function get_date_offset($date) {
    $timezone = new \DateTimeZone('Africa/Cairo');
    $datetime = new \DateTime($date, $timezone);
    return timezone_offset_get($datetime, 'UTC');
}

$date = '0000-00-00 00:00:00';

for ($i = 0; $i < PHP_INT_MAX; $i++) {
    $date = gmdate("Y-m-d H:i:s", PHP_INT_MIN + $i);
    echo get_date_offset($date). "\n";
}

Resulted in this output:

/home/dan/php-src/ext/date/lib/tm2unixtime.c:403:4: runtime error: signed integer overflow: -9223372036854775808 - 7509 cannot be represented in type 'long long int'

But I expected this output instead:

PHP Version

8.4.2

Operating System

ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions