Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Potential signed-to-unsigned conversion in TIFF dimension parsing

Đang mở Phù hợp với người mới
#24,196 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, php
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại ext/standard/image.c, trong php_handle_tiff(), đặc biệt là phần xử lý TAG_FMT_SSHORT và các phép gán IMAGEWIDTH/IMAGEHEIGHT được nêu trong issue. Kiểm tra cách xác thực kiểu trường kích thước TIFF và chạy các bài kiểm thử hình ảnh/TIFF liên quan. Công việc hoàn tất khi các giá trị âm có dấu không thể trở thành kích thước, trong khi các kích thước SHORT hoặc LONG không dấu hợp lệ vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 59 phút
Pull request đã merge (30 ngày)
155

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của php/php-src

Tất cả issue của php/php-src

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.