`Time\Duration::__unserialize()` accepts a "negative zero" payload.
维护者通常 1 天内回复
@TimWolla 已经在做这个了。
开始于 2026年10月23日。
评估
调研方向
首先在 PHP 源代码中找到 Time\Duration::__unserialize(),并阅读其验证逻辑,以及拒绝负秒数和超出范围的纳秒数的检查。复现提供的 payload,并检查负数标志为 true 时零值如何处理。完成标准是:反序列化以指定异常拒绝该值,或将其规范化为非负零,并添加覆盖该 payload 的回归测试。
由索引模型根据 Issue 内容生成。
描述
Description
The following code:
<?php
$payload = 'O:13:"Time\Duration":3:{s:7:"seconds";i:0;s:11:"nanoseconds";i:0;s:8:"negative";b:1;}';
$d = unserialize($payload);
var_dump($d->negative); // expected: exception, or false. actual: true
var_dump(Time\Duration::compare($d, Time\Duration::fromSeconds(0))); // int(0)
var_dump($d->absolute()->negative); // actual: true (absolute() of a value is still "negative")
echo json_encode($d), "\n"; // actual: {"seconds":0,"nanoseconds":0,"negative":true}
echo serialize(Time\Duration::fromSeconds(0)->negate()), "\n"; // canonical zero: ...s:8:"negative";b:0;}
// For comparison, other non-canonical payloads are rejected:
try {
unserialize('O:13:"Time\Duration":3:{s:7:"seconds";i:-1;s:11:"nanoseconds";i:0;s:8:"negative";b:0;}');
} catch (Exception $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
Expected: an exception ("Invalid serialization data for Time\Duration object"), as for the other non-canonical payloads (negative seconds, nanoseconds >= 1e9), or a canonicalized zero with $negative === false. No public factory or arithmetic method can produce a zero duration with $negative === true.
Actual: the object is created with seconds = 0, nanoseconds = 0, negative = true. compare() and == treat it as zero, but the public $negative property, json_encode(), serialize() and absolute() all expose the non-canonical sign.
PHP Version
PHP 8.6.0RC3 (cli) (built: Oct 20 2026 18:44:56) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0RC3, Copyright © Zend by Perforce
with Zend OPcache v8.6.0RC3, Copyright ©, by Zend by Perforce
Operating System
MacOS
- 主要语言
- C
- 星标
- 40.7k
- 派生
- 8.3k
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 151
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php/php-src 的其他 Issue
-
sapi/fpm/tests/tester.inc can send SIGUSR2 to pid 0, killing run-tests.php可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
zend_set_local_var() overwrites existing compiled variable (CV) zval without calling zval_ptr_dtor()可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Case-insensitive substr_compare, ksort, krsort are still locale-dependent可能已有人在做 @lazerg 于 3 天前认领。 未关闭Bug Extension: standard Status: Verified
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
master: part of the mbstring bailout fix got lost in a merge可能已有人在做 @lazerg 于 4 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
difficulty: easy
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 76/100
ChefKissInc/Inferno#319 ·
-
llvm-tools
难度 1/5 1 小时以内 新手友好度 72/100
llvm/llvm-project#235522 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100