Skip to content

Commit e2a2205

Browse files
author
Ulf Wendel
committed
Test for what Andrey has found with 16M packets
1 parent 028bd4b commit e2a2205

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
--TEST--
2+
INSERT and packet overflow
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--INI--
9+
memory_limit=256M
10+
--FILE--
11+
<?php
12+
require('connect.inc');
13+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14+
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
15+
16+
if (!$res = mysqli_query($link, "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"))
17+
printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
18+
19+
if (!$row = mysqli_fetch_assoc($res))
20+
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
21+
22+
mysqli_free_result($res);
23+
24+
if (0 === ($org_max_allowed_packet = (int)$row['Value']))
25+
printf("[004] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
26+
27+
$max_len = pow(2, 24);
28+
if ($org_max_allowed_packet < $max_len) {
29+
if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . ($max_len + 100)))
30+
printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31+
}
32+
mysqli_close($link);
33+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
34+
printf("[006] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
35+
36+
if (!$res = mysqli_query($link, "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"))
37+
printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38+
39+
if (!$row = mysqli_fetch_assoc($res))
40+
printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41+
42+
mysqli_free_result($res);
43+
44+
if (0 === ($max_allowed_packet = (int)$row['Value']))
45+
printf("[009] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
46+
47+
$max_len = pow(2, 24);
48+
if ($max_allowed_packet < $max_len) {
49+
printf("[010] Failed to change max_allowed_packet");
50+
}
51+
52+
if (!mysqli_query($link, "CREATE TABLE test(col_blob LONGBLOB) ENGINE=" . $engine))
53+
printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54+
55+
$query_prefix = 'INSERT INTO test(col_blob) VALUES ("';
56+
$query_postfix = '")';
57+
$query_len = strlen($query_prefix) + strlen($query_postfix);
58+
$com_query_len = 1;
59+
60+
61+
$blob = str_repeat('a', $max_len - $com_query_len - $query_len);
62+
$query = sprintf("%s%s%s", $query_prefix, $blob, $query_postfix);
63+
64+
if (!mysqli_query($link, $query))
65+
printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
66+
67+
if (!$res = mysqli_query($link, "SELECT col_blob FROM test"))
68+
printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
69+
70+
if (!$row = mysqli_fetch_assoc($res)) {
71+
printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
72+
} else {
73+
if ($row['col_blob'] != $blob) {
74+
printf("[015] Blob seems wrong, dumping data\n");
75+
var_dump(strlen($row['col_blob']));
76+
var_dump(strlen($blob));
77+
}
78+
mysqli_free_result($res);
79+
}
80+
81+
if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . $org_max_allowed_packet))
82+
printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
83+
84+
mysqli_close($link);
85+
86+
print "done!";
87+
?>
88+
--CLEAN--
89+
<?php
90+
require_once("clean_table.inc");
91+
?>
92+
--EXPECTF--
93+
done!

0 commit comments

Comments
 (0)