com php-src: Fix #72688: preg_match missing group names in matches: NEWS ext/pcre/php_pcre.c ext/pcre/ tests/bug72688.phpt
| From: | Christoph Michael Becker | Date: | Wed, 27 Jul 2016 16:50:52 +0000 |
| Subject: | com php-src: Fix #72688: preg_match missing group names in matches: NEWS ext/pcre/php_pcre.c ext/pcre/ tests/bug72688.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93423@lists.php.net to get a copy of this message | ||
Commit: 315c0536c20619478fc548b782132cd65286018f
Author: Christoph M. Becker <cmb@php.net> Wed, 27 Jul 2016 18:50:52 +0200
Parents: cc125f277b50e0f90fc8033fe7f47d2446389a15
Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=315c0536c20619478fc548b782132cd65286018f
Log:
Fix #72688: preg_match missing group names in matches
We have to multiply with 0x100 to properly scale the high byte.
Bugs:
https://bugs.php.net/72688
Changed paths:
M NEWS
M ext/pcre/php_pcre.c
A ext/pcre/tests/bug72688.phpt
Diff:
diff --git a/NEWS b/NEWS
index bd65b76..204defd 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,8 @@ PHP NEWS
- Intl:
. Partially fixed #72506 (idn_to_ascii for UTS #46 incorrect for long domain
names). (cmb)
+- PCRE:
+ . Fixed bug #72688 (preg_match missing group names in matches). (cmb)
- PDO_pgsql:
. Fixed bug #70313 (PDO statement fails to throw exception). (Matteo)
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 6b258b9..ddc5d76 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -215,7 +215,7 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D
}
while (ni++ < name_cnt) {
- name_idx = 0xff * (unsigned char)name_table[0] + (unsigned char)name_table[1];
+ name_idx = 0x100 * (unsigned char)name_table[0] + (unsigned char)name_table[1];
subpat_names[name_idx] = name_table + 2;
if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0)
> 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric named subpatterns are not
allowed");
diff --git a/ext/pcre/tests/bug72688.phpt b/ext/pcre/tests/bug72688.phpt
new file mode 100644
index 0000000..715743c
--- /dev/null
+++ b/ext/pcre/tests/bug72688.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #72688 (preg_match missing group names in matches)
+--FILE--
+<?php
+
+$pattern = [];
+for ($i = 0; $i < 300; $i++) {
+ $pattern[] = "(?'group{$i}'{$i}$)";
+}
+$fullPattern = '/' . implode('|', $pattern) . '/uix';
+
+preg_match($fullPattern, '290', $matches);
+
+var_dump($matches['group290']);
+?>
+--EXPECT--
+string(3) "290"