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

Potential signed-to-unsigned conversion in TIFF dimension parsing

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 ext/standard/image.c 中的 php_handle_tiff() 开始,重点检查 TAG_FMT_SSHORT 的处理以及 issue 中指出的 IMAGEWIDTH/IMAGEHEIGHT 赋值。检查 TIFF 尺寸字段类型如何进行验证,并运行相关的图像/TIFF 测试。完成标准是:负的有符号值不能成为尺寸,同时有效的无符号 SHORT 或 LONG 尺寸仍能正常工作。

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

描述

Bug Status: Needs Triage
Description

Hi, It seemed to me that a negative signed value could potentially be converted to a large unsigned value here.

A potential signed-to-unsigned conversion issue exists in php_handle_tiff() when processing TIFF image dimensions.

The entry_value variable is declared as size_t, while the TAG_FMT_SSHORT case assigns the return value of php_ifd_get16s() to it:

case TAG_FMT_SSHORT:
entry_value = php_ifd_get16s(dir_entry+8, motorola_intel);
break;

php_ifd_get16s() returns a signed 16-bit value. Therefore, a negative value from the TIFF input can be converted to a large unsigned size_t value.

If such an entry is subsequently identified as TAG_IMAGEWIDTH or TAG_IMAGEHEIGHT, the converted value is assigned to width or height:

case TAG_IMAGEWIDTH:
case TAG_COMP_IMAGEWIDTH:
width = entry_value;
break;

case TAG_IMAGEHEIGHT:
case TAG_COMP_IMAGEHEIGHT:
height = entry_value;
break;

For example, a signed value of -1 can be converted to the maximum value of size_t instead of remaining negative.

According to the TIFF 6.0 specification, ImageWidth and ImageLength use the SHORT or LONG types, where SHORT is an unsigned 16-bit integer. The reader is expected to validate the field type.

Impact

A malformed TIFF containing a negative SSHORT value for an image dimension can therefore cause the parser to produce an unexpectedly large width or height.

Proposed solution

Validate the signed value before assigning it to the unsigned entry_value variable and reject negative values.

PHP Version
PHP 8.3.31 (CLI)
Operating System

Ubuntu 24.04

主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 24 分钟
30 天内合并 PR
157

环境准备

  • 没有 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 摘要。