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