Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time() and friends have Y2038 problem on 64 Windows #17856

Open
cmb69 opened this issue Feb 18, 2025 · 3 comments
Open

time() and friends have Y2038 problem on 64 Windows #17856

cmb69 opened this issue Feb 18, 2025 · 3 comments

Comments

@cmb69
Copy link
Member

cmb69 commented Feb 18, 2025

Description

I travelled 15 years into the future, and run the following code:

<?php
var_dump(time());

Resulted in this output:

int(-2081770632)

But I expected this output instead:

int(2213196664)

The problem is

tv->tv_sec = (long)(ff / 1000000Ui64);

Casting to long is appropriate since the declaration of struct timeval in WinSock2.h is:

struct timeval {
        long    tv_sec;         /* seconds */
        long    tv_usec;        /* and microseconds */
};

However, long is a 32bit value on LLP64 architectures.

One may argue that time travel is not supportable, but maybe we should heed the POSIX 7 advise:

Applications should use the clock_gettime() function instead of the obsolescent gettimeofday() function.

gettimeofday() has been removed from POSIX 8 altogether.

PHP Version

any

Operating System

Windows

@nielsdos
Copy link
Member

A bit related to #14141

@cmb69
Copy link
Member Author

cmb69 commented Feb 18, 2025

Wow, serious mess here. While we're checking for the availability of gettimeofday() during configuration, setting HAVE_GETTIMEOFDAY if so, in a couple of places we just call the function even though it might not be available. Sometimes we check whether the gettimeofday() call failed, and sometimes we just assume it cannot fail. As fallback we're using time(), but still prefer gettimeofday() even when we don't use the microseconds.

And those calls to gettimeofday() are spread all over the place.

@cmb69
Copy link
Member Author

cmb69 commented Feb 18, 2025

Oh, forgeot: instead of using clock_gettime() we can likely use timespec_get() which is a C11 function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants