Skip to content

BMP width above INT_MAX is published as a negative HTML attribute #25949

Backlog

Description

@kid-lxy

Description

The following code:

<?php
$bmp = 'BM' . pack('VVV', 54, 0, 54)
     . pack('VVV', 40, 0x80000001, 1)
     . pack('vv', 1, 24)
     . str_repeat("\0", 24);
var_dump(getimagesizefromstring($bmp));

Resulted in this output:

array(8) {
  [0]=>
  int(2147483649)
  [1]=>
  int(1)
  [2]=>
  int(6)
  [3]=>
  string(30) "width="-2147483647" height="1""
  ["bits"]=>
  int(24)
  ["mime"]=>
  string(9) "image/bmp"
  ["width_unit"]=>
  string(2) "px"
  ["height_unit"]=>
  string(2) "px"
}

But I expected this output instead:

bool(false)

ext/standard/image.c:127 assembles the signed BMP biWidth bytes directly into unsigned result->width without rejecting values above INT_MAX, and the shared formatter at image.c:1594 prints that unsigned value with %d. The malformed width must be rejected instead of being returned as 2147483649 and rendered as -2147483647.

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

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