php / php/php-src

time() and friends have Y2038 problem on 64 Windows

未关闭
#17,856 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: date Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 win32/time.c 中 time() 获取并转换 tv_sec 的链接行附近开始,然后检查报告中描述的 Windows LLP64 限制以及相关的 time APIs。在 64 位 Windows 上确认其行为,并将完成定义为:在 2038 年之后返回正确的正时间戳,且不再出现当前的 32 位溢出。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。