xref: /PHP-8.3/ext/gd/tests/createfromwbmp2.phpt (revision a375d547)
1--TEST--
2imagecreatefromwbmp with invalid wbmp
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!GD_BUNDLED) die("skip requires bundled GD library\n");
8?>
9--FILE--
10<?php
11$filename = __DIR__ . '/_tmp.wbmp';
12$fp = fopen($filename,"wb");
13if (!$fp) {
14    exit("Failed to create <$filename>");
15}
16
17//write header
18$c = 0;
19fputs($fp, chr($c), 1);
20fputs($fp, $c, 1);
21
22//write width = 2^32 / 4 + 1
23$c = 0x84;
24fputs($fp, chr($c), 1);
25$c = 0x80;
26fputs($fp, chr($c), 1);
27fputs($fp, chr($c), 1);
28fputs($fp, chr($c), 1);
29$c = 0x01;
30fputs($fp, chr($c), 1);
31
32/*write height = 4*/
33$c = 0x04;
34fputs($fp, chr($c), 1);
35
36/*write some data to cause overflow*/
37for ($i=0; $i<10000; $i++) {
38    fwrite($fp, chr($c), 1);
39}
40
41fclose($fp);
42$im = imagecreatefromwbmp($filename);
43unlink($filename);
44?>
45--EXPECTF--
46Warning: imagecreatefromwbmp(): Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
47 in %s on line %d
48
49Warning: imagecreatefromwbmp(): "%s" is not a valid WBMP file in %s on line %d
50