Skip to content

Commit 6df6209

Browse files
committed
Add regression test for GH-24578
Fixes #24578.
1 parent 7815b6c commit 6df6209

4 files changed

Lines changed: 102 additions & 17 deletions

File tree

‎.github/actions/apt-x32/action.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ runs:
99
OPCACHE_TLS_TESTS_DEPS="gcc clang lld"
1010
1111
export DEBIAN_FRONTEND=noninteractive
12-
dpkg --add-architecture i386
13-
apt-get update -y | true
12+
sudo dpkg --add-architecture i386
13+
sudo env DEBIAN_FRONTEND=noninteractive apt-get update -y | true
1414
# TODO: Reenable postgresql + postgresql-contrib packages once they work again.
15-
apt-get install -y \
15+
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y \
1616
autoconf \
1717
bison \
1818
curl \

‎.github/actions/install-linux-x32/action.yml‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ runs:
55
- shell: bash
66
run: |
77
set -x
8-
make install
9-
mkdir -p /etc/php.d
10-
chmod 777 /etc/php.d
11-
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
12-
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
13-
echo opcache.enable_cli=1 >> /etc/php.d/opcache.ini
14-
echo opcache.protect_memory=1 >> /etc/php.d/opcache.ini
15-
echo opcache.preload_user=root >> /etc/php.d/opcache.ini
8+
sudo make install
9+
sudo mkdir -p /etc/php.d
10+
sudo chmod 777 /etc/php.d
11+
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock | sudo tee /etc/php.d/mysqli.ini > /dev/null
12+
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock | sudo tee /etc/php.d/pdo_mysql.ini > /dev/null
13+
echo opcache.enable_cli=1 | sudo tee /etc/php.d/opcache.ini > /dev/null
14+
echo opcache.protect_memory=1 | sudo tee -a /etc/php.d/opcache.ini > /dev/null
15+
echo opcache.preload_user=root | sudo tee -a /etc/php.d/opcache.ini > /dev/null

‎.github/workflows/test-suite.yml‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,11 @@ jobs:
232232
name: "LINUX_X32_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
233233
runs-on: ubuntu-24.04
234234
timeout-minutes: 180
235-
container:
236-
image: ubuntu:${{ fromJson(inputs.branch).config.ubuntu_version }}
237235
env:
238-
MYSQL_TEST_HOST: mysql
239-
PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test
240-
PDO_MYSQL_TEST_HOST: mysql
241-
PDO_FIREBIRD_TEST_DSN: firebird:dbname=firebird:test.fdb
236+
MYSQL_TEST_HOST: 127.0.0.1
237+
PDO_MYSQL_TEST_DSN: mysql:host=127.0.0.1;dbname=test
238+
PDO_MYSQL_TEST_HOST: 127.0.0.1
239+
PDO_FIREBIRD_TEST_DSN: firebird:dbname=localhost:test.fdb
242240
services:
243241
mysql:
244242
image: mysql:8.4

‎ext/opcache/tests/jit/gh24578.phpt‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
--TEST--
2+
GH-24578 (Function JIT produces an incorrect result in a string-scanning loop)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=64M
8+
opcache.jit=function
9+
--EXTENSIONS--
10+
opcache
11+
--FILE--
12+
<?php
13+
final class Repro {
14+
public static function skipComment(string $sql, int $position): int {
15+
$byte = $sql[$position];
16+
$next = $sql[$position + 1] ?? '';
17+
if ($byte === '/' && $next === '*') {
18+
$end = strpos($sql, '*/', $position + 2);
19+
return $end === false ? strlen($sql) : $end + 2;
20+
}
21+
$dashes = $byte === '-' && $next === '-' && strspn($sql[$position + 2] ?? "\n", " \t\r\n") === 1;
22+
if ($byte !== '#' && !$dashes) {
23+
return $position;
24+
}
25+
$end = strpos($sql, "\n", $position);
26+
return $end === false ? strlen($sql) : $end + 1;
27+
}
28+
29+
public static function skipQuoted(string $sql, int $position): int {
30+
$quote = $sql[$position];
31+
$length = strlen($sql);
32+
$stops = $quote === '`' ? '`' : $quote . '\\';
33+
$position++;
34+
while ($position < $length) {
35+
$position += strcspn($sql, $stops, $position);
36+
if ($position >= $length) {
37+
break;
38+
}
39+
if ($sql[$position] === '\\') {
40+
$position += 2;
41+
} elseif (($sql[$position + 1] ?? '') === $quote) {
42+
$position += 2;
43+
} else {
44+
return $position + 1;
45+
}
46+
}
47+
return $length;
48+
}
49+
50+
public static function interpolate(string $sql, array $params): ?string {
51+
$length = strlen($sql);
52+
$count = count($params);
53+
$text = '';
54+
$used = 0;
55+
$copied = 0;
56+
$position = 0;
57+
while ($position < $length) {
58+
$position += strcspn($sql, "?'\"`#-/", $position);
59+
if ($position >= $length) {
60+
break;
61+
}
62+
$byte = $sql[$position];
63+
if ($byte === '?') {
64+
$text .= substr($sql, $copied, $position - $copied) . (string) $params[$used];
65+
$used++;
66+
$position++;
67+
$copied = $position;
68+
} elseif ($byte === "'" || $byte === '"' || $byte === '`') {
69+
$position = self::skipQuoted($sql, $position);
70+
} else {
71+
$after = self::skipComment($sql, $position);
72+
$position = $after === $position ? $position + 1 : $after;
73+
}
74+
}
75+
return $used === $count ? $text . substr($sql, $copied) : null;
76+
}
77+
}
78+
79+
// A minus or slash without a following comment delimiter must not make the scanner stop.
80+
var_dump(Repro::interpolate('SELECT ? AS v', [3]));
81+
var_dump(Repro::interpolate('SELECT 5 -', []));
82+
var_dump(Repro::interpolate('SELECT 5 / 2', []));
83+
?>
84+
--EXPECT--
85+
string(13) "SELECT 3 AS v"
86+
string(10) "SELECT 5 -"
87+
string(12) "SELECT 5 / 2"

0 commit comments

Comments
 (0)