Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`Time\Duration::__unserialize()` accepts a "negative zero" payload.

已关闭 适合新手
#24,505 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@TimWolla 已经在做这个了。

开始于 2026年10月23日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
71/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

首先在 PHP 源代码中找到 Time\Duration::__unserialize(),并阅读其验证逻辑,以及拒绝负秒数和超出范围的纳秒数的检查。复现提供的 payload,并检查负数标志为 true 时零值如何处理。完成标准是:反序列化以指定异常拒绝该值,或将其规范化为非负零,并添加覆盖该 payload 的回归测试。

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

描述

Bug Status: Needs Triage
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 模板
  • 阅读贡献指南

从这里开始

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

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

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