getimagesize(): negative TIFF dimensions are narrowed into huge unsigned sizes

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

阅读 ext/standard/image.c:823-850,重点关注 TIFF 尺寸在返回前如何解析和检查。使用提供的 getimagesizefromstring() 示例重现问题;当负尺寸返回 bool(false),且有效的 TIFF 尺寸仍能正常工作时,即为完成。

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

描述

Bug Status: Needs Triage
Description

The following code:

<?php
$tiff = "II\x2a\x00" . pack('V', 8) . pack('v', 2)
      . pack('vvVv', 256, 8, 1, 0xFFFF) . "\0\0"
      . pack('vvVv', 257, 8, 1, 0xFFFE) . "\0\0"
      . pack('V', 0);
var_dump(getimagesizefromstring($tiff));

Resulted in this output:

array(7) {
  [0]=>
  int(4294967295)
  [1]=>
  int(4294967294)
  [2]=>
  int(7)
  [3]=>
  string(22) "width="-1" height="-2""
  ["mime"]=>
  string(10) "image/tiff"
  ["width_unit"]=>
  string(2) "px"
  ["height_unit"]=>
  string(2) "px"
}

But I expected this output instead:

bool(false)

The signed TIFF values are assigned to size_t and then narrowed into unsigned result fields in ext/standard/image.c:823-850, while the guard at line 846 checks only that the dimensions are nonzero. Negative dimensions must be rejected rather than sign-extended and published as 4294967295 and 4294967294.

PHP Version
PHP 8.7.0-dev (cli) (built: Nov 29 2026 03:42:09) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.7.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce
Operating System

Ubuntu 24.04.5 LTS

主要语言
C
星标
41.9k
派生
8.5k
平均合并
2 天 17 小时
30 天内合并 PR
111

环境准备

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