php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81265 getimagesize returns 0 for 256px ICO images
Submitted: 2021-07-16 00:40 UTC Modified: -
From: george at dietrich dot app Assigned:
Status: Closed Package: GetImageSize related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
 [2021-07-16 00:40 UTC] george at dietrich dot app
Description:
------------
Using getimagesize on a .ico file that is 256px wide or 256px high will result in that value being returned at 0 due to the value being stored as 0 in the header as per https://devblogs.microsoft.com/oldnewthing/20101022-00/?p=12473 and https://en.wikipedia.org/wiki/ICO_(file_format):

> The value 0 is accepted as representing a width or height of 256.

> Can be any number between 0 and 255. Value 0 means 256 pixels.

Wasn't sure what version to pick as the bug is like 14 years old (introduced via https://github.com/php/php-src/commit/c76e8e03a1cc67d695b1fa024924a462ca897434), so I just with with irrelevant as it's been an issue since 5.3.0.

Test script:
---------------
var_dump(getimagesize("https://raw.githubusercontent.com/toy/image_size/master/spec/images/ico/32x256.ico"));

Expected result:
----------------
array(6) {
  [0]=> int(32)
  [1]=> int(256)
  [2]=> int(17)
  [3]=> string(21) "width="32" height="256""
  ["bits"]=> int(8)
  ["mime"]=> string(24) "image/vnd.microsoft.icon"
}

Actual result:
--------------
array(6) {
  [0]=> int(32)
  [1]=> int(0)
  [2]=> int(17)
  [3]=> string(21) "width="32" height="0""
  ["bits"]=> int(8)
  ["mime"]=> string(24) "image/vnd.microsoft.icon"
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-16 01:06 UTC] george at dietrich dot app
The following pull request has been associated:

Patch Name: Fix bug 81265: Set ICO height/width to 256 if 0
On GitHub:  https://github.com/php/php-src/pull/7247
Patch:      https://github.com/php/php-src/pull/7247.patch
 [2021-07-16 08:08 UTC] git@php.net
Automatic comment on behalf of Blacksmoke16 (author) and nikic (committer)
Revision: https://github.com/php/php-src/commit/8f97f82e356f2410f7f6fff3ed6fe3e51709ff6c
Log: Fix bug #81265: getimagesize returns 0 for 256px ICO images
 [2021-07-16 08:08 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC