xref: /PHP-7.4/ext/mysqli/tests/bug35759.phpt (revision e3e67b72)
1--TEST--
2Bug #35759 (mysqli_stmt_bind_result() makes huge allocation when column empty)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10
11    require_once("connect.inc");
12    $col_num= 1000;
13
14    $mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
15    $mysql->query("DROP TABLE IF EXISTS test");
16    $create = "CREATE TABLE test (a0 MEDIUMBLOB NOT NULL DEFAULT ''";
17    $i= 0;
18    while (++$i < $col_num) {
19        $create .= ", a$i MEDIUMBLOB NOT NULL DEFAULT ''";
20    }
21    $create .= ") ENGINE=MyISAM"; // doesn't work with InnoDB, which is default in 5.5
22
23    if (!$mysql->query($create)) {
24        if (1101 == $mysql->errno) {
25            /* SQL strict mode - [1101] BLOB/TEXT column 'a0' can't have a default value */
26            print "done!";
27            exit(0);
28        }
29        printf("[001] [%d] %s\n", $mysql->errno, $mysql->error);
30    }
31
32    if (!$mysql->query("INSERT INTO test (a0) VALUES ('')"))
33        printf("[002] [%d] %s\n", $mysql->errno, $mysql->error);
34
35    $stmt = $mysql->prepare("SELECT * FROM test");
36    if ($stmt) {
37
38        $stmt->execute();
39        $stmt->store_result();
40        for ($i = 0; $i < $col_num; $i++) {
41            $params[] = &$col_num;
42        }
43        call_user_func_array(array($stmt, "bind_result"), $params);
44        $stmt->fetch();
45
46        $stmt->close();
47    } else {
48        printf("[003] [%d] %s\n", $mysql->errno, $mysql->error);
49    }
50
51    $mysql->close();
52
53    echo "done!";
54?>
55--CLEAN--
56<?php require("clean_table.inc"); ?>
57--EXPECT--
58done!
59