xref: /PHP-8.2/ext/mysqli/tests/bug_bits.phpt (revision b5a14e6c)
1--TEST--
2Bug (Incorrectly decoding bit values / Malformed server packet. Field length pointing)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11
12require_once("connect.inc");
13if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
14    printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
15}
16
17if (!$link->query("DROP TABLE IF EXISTS bug_bits")) {
18    printf("[002] [%d] %s\n", $link->errno, $link->error);
19}
20
21if (!$link->query("CREATE TABLE `bug_bits` (`inty` bigint(20) unsigned NOT NULL DEFAULT '0', `bitty` bit(64) NOT NULL DEFAULT b'0')")) {
22    printf("[003] [%d] %s\n", $link->errno, $link->error);
23}
24
25$insertQuery = "INSERT INTO `bug_bits` VALUES (18446744073709551615, 18446744073709551615)".
26               ",(18446744073709551614, 18446744073709551614)".
27               ",(4294967296, 4294967296)".
28               ",(4294967295, 4294967295)".
29               ",(2147483648, 2147483648)".
30               ",(2147483647, 2147483647)".
31               ",(1, 1)";
32if (!$link->query($insertQuery)) {
33    printf("[004] [%d] %s\n", $link->errno, $link->error);
34}
35
36if (!($res = $link->query("SELECT * FROM `bug_bits`"))) {
37    printf("[005] [%d] %s\n", $link->errno, $link->error);
38}
39
40while ($row = $res->fetch_assoc()) {
41    var_dump($row);
42}
43
44$link->close();
45
46echo "Done\n";
47?>
48--CLEAN--
49<?php
50require_once("connect.inc");
51if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
52    printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
53
54if (!mysqli_query($link, "DROP TABLE IF EXISTS bug_bits"))
55    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56
57mysqli_close($link);
58?>
59--EXPECT--
60array(2) {
61  ["inty"]=>
62  string(20) "18446744073709551615"
63  ["bitty"]=>
64  string(20) "18446744073709551615"
65}
66array(2) {
67  ["inty"]=>
68  string(20) "18446744073709551614"
69  ["bitty"]=>
70  string(20) "18446744073709551614"
71}
72array(2) {
73  ["inty"]=>
74  string(10) "4294967296"
75  ["bitty"]=>
76  string(10) "4294967296"
77}
78array(2) {
79  ["inty"]=>
80  string(10) "4294967295"
81  ["bitty"]=>
82  string(10) "4294967295"
83}
84array(2) {
85  ["inty"]=>
86  string(10) "2147483648"
87  ["bitty"]=>
88  string(10) "2147483648"
89}
90array(2) {
91  ["inty"]=>
92  string(10) "2147483647"
93  ["bitty"]=>
94  string(10) "2147483647"
95}
96array(2) {
97  ["inty"]=>
98  string(1) "1"
99  ["bitty"]=>
100  string(1) "1"
101}
102Done
103