1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
--TEST--
Bug GH-15432 (Heap corruption when querying a vector/PHP crashes when processing a MySQL DB query with a new Vector format introduced in MySQL 9.0)
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require 'connect.inc';
$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
if ($link === false) {
die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
}
if ($link->server_version < 90000 || $link->server_version >= 10_00_00) {
die("skip MySQL 9.0.0+ needed");
}
?>
--FILE--
<?php
require 'connect.inc';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$expected = '00000040000040400000a040';
mysqli_query($link, "DROP TABLE IF EXISTS test");
mysqli_query($link, "CREATE TABLE test(vectorfield VECTOR)");
mysqli_query($link, 'INSERT INTO test VALUES (TO_VECTOR("[2, 3, 5]"))');
// Textual protocol
$result = mysqli_query($link, "SELECT vectorfield FROM test")->fetch_column();
$value = bin2hex($result);
if($value !== $expected) {
printf("[001] Expecting %s/%s, got %s/%s\n",
gettype($expected), $expected,
gettype($value), $value);
}
// Binary protocol
$result = $link->execute_query("SELECT vectorfield FROM test")->fetch_column();
$value = bin2hex($result);
if($value !== $expected) {
printf("[002] Expecting %s/%s, got %s/%s\n",
gettype($expected), $expected,
gettype($value), $value);
}
// Testing inverse to make sure the value hasn't been changed
$expected = '[2.00000e+00,3.00000e+00,5.00000e+00]';
$result = $link->execute_query("SELECT VECTOR_TO_STRING(0x". $value .")")->fetch_column();
if($result !== $expected) {
printf("[002] Expecting %s/%s, got %s/%s\n",
gettype($expected), $expected,
gettype($result), $result);
}
echo "OK";
?>
--CLEAN--
<?php
require_once 'clean_table.inc';
?>
--EXPECT--
OK
|