Skip to content

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

Backlog

Description

@kid-lxy

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

Activity

  1. lazerg commented on Dec 1, 2026

    @lazerg
    Contributor

    There's already an open PR that touches this: #24197. It rejects negative 16-bit TIFF dimensions in php_handle_tiff().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions