Skip to content

Commit 1d9da89

Browse files
ext/gd: fix imagecreate_error_oversized.phpt on 32-bit
On 32-bit platforms 4294967296 is a float that doesn't fit in an int, so imagecreate() and imagecreatetruecolor() throw a TypeError before they check the range, and the test fails. It has failed in the LINUX_X32_DEBUG_ZTS job since it was added in 66c0f52. Move that value to a test for 64-bit platforms. The values that remain, PHP_INT_MAX and 2147483647, are valid ints on all platforms.
1 parent a7598d3 commit 1d9da89

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎ext/gd/tests/imagecreate_error_oversized.phpt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ imagecreate()/imagecreatetruecolor(): oversized dimensions produce a correct err
44
gd
55
--FILE--
66
<?php
7-
foreach ([PHP_INT_MAX, 2147483647, 4294967296] as $v) {
7+
foreach ([PHP_INT_MAX, 2147483647] as $v) {
88
try { imagecreate($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
99
try { imagecreate(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
1010
try { imagecreatetruecolor($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
@@ -20,7 +20,3 @@ ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less
2020
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
2121
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
2222
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
23-
ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
24-
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
25-
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
26-
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
imagecreate()/imagecreatetruecolor(): dimensions that don't fit in 32 bits produce a correct error message
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
8+
?>
9+
--FILE--
10+
<?php
11+
$v = 4294967296;
12+
try { imagecreate($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
13+
try { imagecreate(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
14+
try { imagecreatetruecolor($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
15+
try { imagecreatetruecolor(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
16+
?>
17+
--EXPECTF--
18+
ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
19+
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
20+
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
21+
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d

0 commit comments

Comments
 (0)