|
| 1 | +--TEST-- |
| 2 | +GH-18005: imagesetstyle, imagefilter, imagecrop array values type checks |
| 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 | +class A {} |
| 12 | +$img = imagecreatetruecolor(1, 1); |
| 13 | +try { |
| 14 | + imagesetstyle($img, [0, new A()]); |
| 15 | +} catch (\TypeError $e) { |
| 16 | + echo $e->getMessage() . PHP_EOL; |
| 17 | +} |
| 18 | +try { |
| 19 | + imagesetstyle($img, [0, PHP_INT_MIN]); |
| 20 | +} catch (\TypeError $e) { |
| 21 | + echo $e->getMessage() . PHP_EOL; |
| 22 | +} |
| 23 | +try { |
| 24 | + imagefilter($img, IMG_FILTER_SCATTER, 0, 0, [new A()]); |
| 25 | +} catch (\ValueError $e) { |
| 26 | + echo $e->getMessage() . PHP_EOL; |
| 27 | +} |
| 28 | +try { |
| 29 | + imagefilter($img, IMG_FILTER_SCATTER, 0, 0, [-1]); |
| 30 | +} catch (\ValueError $e) { |
| 31 | + echo $e->getMessage() . PHP_EOL; |
| 32 | +} |
| 33 | +try { |
| 34 | + imagecrop($img, ["x" => PHP_INT_MIN, "y" => 0, "width" => 0, "height" => 0]); |
| 35 | +} catch (\ValueError $e) { |
| 36 | + echo $e->getMessage() . PHP_EOL; |
| 37 | +} |
| 38 | +try { |
| 39 | + imagecrop($img, ["x" => 0, "y" => PHP_INT_MIN, "width" => 0, "height" => 0]); |
| 40 | +} catch (\ValueError $e) { |
| 41 | + echo $e->getMessage() . PHP_EOL; |
| 42 | +} |
| 43 | +try { |
| 44 | + imagecrop($img, ["x" => 0, "y" => 0, "width" => PHP_INT_MAX, "height" => 0]); |
| 45 | +} catch (\ValueError $e) { |
| 46 | + echo $e->getMessage() . PHP_EOL; |
| 47 | +} |
| 48 | +try { |
| 49 | + imagecrop($img, ["x" => 0, "y" => 0, "width" => 0, "height" => PHP_INT_MAX]); |
| 50 | +} catch (\ValueError $e) { |
| 51 | + echo $e->getMessage() . PHP_EOL; |
| 52 | +} |
| 53 | + |
| 54 | +try { |
| 55 | + imagecrop($img, ["x" => new A(), "y" => 0, "width" => 0, "height" => 0]); |
| 56 | +} catch (\ValueError $e) { |
| 57 | + echo $e->getMessage() . PHP_EOL; |
| 58 | +} |
| 59 | +try { |
| 60 | + imagecrop($img, ["x" => 0, "y" => new A(), "width" => 0, "height" => 0]); |
| 61 | +} catch (\ValueError $e) { |
| 62 | + echo $e->getMessage() . PHP_EOL; |
| 63 | +} |
| 64 | +try { |
| 65 | + imagecrop($img, ["x" => 0, "y" => 0, "width" => new A(), "height" => 0]); |
| 66 | +} catch (\ValueError $e) { |
| 67 | + echo $e->getMessage() . PHP_EOL; |
| 68 | +} |
| 69 | +try { |
| 70 | + imagecrop($img, ["x" => 0, "y" => 0, "width" => 0, "height" => new A()]); |
| 71 | +} catch (\ValueError $e) { |
| 72 | + echo $e->getMessage() . PHP_EOL; |
| 73 | +} |
| 74 | + |
| 75 | +$one = 1; |
| 76 | +var_dump(imagecrop($img, ["x" => &$one, "y" => &$one, "width" => &$one, "height" => &$one])); |
| 77 | +?> |
| 78 | +--EXPECTF-- |
| 79 | +imagesetstyle(): Argument #2 ($style) must only have elements of type int, A given |
| 80 | +imagesetstyle(): Argument #2 ($style) elements must be between %i and %d |
| 81 | +imagefilter(): Argument #5 value must be of type int, A given |
| 82 | +imagefilter(): Argument #5 value must be between 0 and 2147483647 |
| 83 | +imagecrop(): Argument #2 ($rectangle) "x" key must be between %i and %d |
| 84 | +imagecrop(): Argument #2 ($rectangle) "y" key must be between %i and %d |
| 85 | +imagecrop(): Argument #2 ($rectangle) "width" key must be between %i and %d |
| 86 | +imagecrop(): Argument #2 ($rectangle) "height" key must be between %i and %d |
| 87 | +imagecrop(): Argument #2 ($rectangle) "x" key must be of type int, A given |
| 88 | +imagecrop(): Argument #2 ($rectangle) "y" key must be of type int, A given |
| 89 | +imagecrop(): Argument #2 ($rectangle) "width" key must be of type int, A given |
| 90 | +imagecrop(): Argument #2 ($rectangle) "height" key must be of type int, A given |
| 91 | +object(GdImage)#2 (0) { |
| 92 | +} |
0 commit comments