time() and friends have Y2038 problem on 64 Windows
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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
https://github.com/php/php-src/blob/3d9a0a0c17c1660116c0699e6be734817d616292/win32/time.c#L46
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in win32/time.c around the linked line where time() obtains and casts tv_sec, then review the Windows LLP64 limitation described in the report and the related time APIs. Confirm the behavior on 64-bit Windows and define completion as returning a correct positive timestamp beyond 2038 without the current 32-bit overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100