xref: /PHP-8.1/ext/pcre/tests/bug76514.phpt (revision bb2f1a68)
1--TEST--
2Bug #76514 Regression in preg_match makes it fail with PREG_JIT_STACKLIMIT_ERROR
3--FILE--
4<?php
5
6$str = '{
7    "config": {
8        "cache-files-ttl": 0,
9        "discard-changes": true
10    },
11    "minimum-stability": "stable",
12    "prefer-stable": false,
13    "provide": {
14        "heroku-sys/cedar": "14.2016.03.22"
15    },
16    "repositories": [
17        {
18            "packagist.org": false
19        },
20        {
21            "type": "package",
22            "package": [
23                {
24                    "type": "metapackage",
25                    "name": "anthonymartin/geo-location",
26                    "version": "v1.0.0",
27                    "require": {
28                        "heroku-sys/php": ">=5.3.0"
29                    },
30                    "replace": [],
31                    "provide": [],
32                    "conflict": []
33                },
34                {
35                    "type": "metapackage",
36                    "name": "aws/aws-sdk-php",
37                    "version": "3.9.4",
38                    "require": {
39                        "heroku-sys/php": ">=5.5"
40                    },
41                    "replace": [],
42                    "provide": [],
43                    "conflict": []
44                },
45                {
46                    "type": "metapackage",
47                    "name": "cloudinary/cloudinary_php",
48                    "version": "dev-master",
49                    "require": {
50                        "heroku-sys/ext-curl": "*",
51                        "heroku-sys/ext-json": "*",
52                        "heroku-sys/php": ">=5.3.0"
53                    },
54                    "replace": [],
55                    "provide": [],
56                    "conflict": []
57                },
58                {
59                    "type": "metapackage",
60                    "name": "doctrine/annotations",
61                    "version": "v1.2.7",
62                    "require": {
63                        "heroku-sys/php": ">=5.3.2"
64                    },
65                    "replace": [],
66                    "provide": [],
67                    "conflict": []
68                },
69                {
70                    "type": "metapackage",
71                    "name": "doctrine/cache",
72                    "version": "v1.6.0",
73                    "require": {
74                        "heroku-sys/php": "~5.5|~7.0"
75                    },
76                    "replace": [],
77                    "provide": [],
78                    "conflict": []
79                },
80                {
81                    "type": "metapackage",
82                    "name": "doctrine/collections",
83                    "version": "v1.3.0",
84                    "require": {
85                        "heroku-sys/php": ">=5.3.2"
86                    },
87                    "replace": [],
88                    "provide": [],
89                    "conflict": []
90                },
91                {
92                    "type": "metapackage",
93                    "name": "doctrine/common",
94                    "version": "v2.6.1",
95                    "require": {
96                        "heroku-sys/php": "~5.5|~7.0"
97                    },
98                    "replace": [],
99                    "provide": [],
100                    "conflict": []
101                },
102                {
103                    "type": "metapackage",
104                    "name": "doctrine/inflector",
105                    "version": "v1.1.0",
106                    "require": {
107                        "heroku-sys/php": ">=5.3.2"
108                    },
109                    "replace": [],
110                    "provide": [],
111                    "conflict": []
112                },
113                {
114                    "type": "metapackage",
115                    "name": "doctrine/lexer",
116                    "version": "v1.0.1",
117                    "require": {
118                        "heroku-sys/php": ">=5.3.2"
119                    },
120                    "replace": [],
121                    "provide": [],
122                    "conflict": []
123                },
124                {
125                    "type": "metapackage",
126                    "name": "geoip/geoip",
127                    "version": "v1.16",
128                    "require": [],
129                    "replace": [],
130                    "provide": [],
131                    "conflict": {
132                        "heroku-sys/ext-geoip": "*"
133                    }
134                },
135                {
136                    "type": "metapackage",
137                    "name": "giggsey/libphonenumber-for-php",
138                    "version": "7.2.5",
139                    "require": {
140                        "heroku-sys/ext-mbstring": "*"
141                    },
142                    "replace": [],
143                    "provide": [],
144                    "conflict": []
145                },
146                {
147                    "type": "metapackage",
148                    "name": "guzzlehttp/guzzle",
149                    "version": "5.3.0",
150                    "require": {
151                        "heroku-sys/php": ">=5.4.0"
152                    },
153                    "replace": [],
154                    "provide": [],
155                    "conflict": []
156                },
157                {
158                    "type": "metapackage",
159                    "name": "guzzlehttp/promises",
160                    "version": "1.0.3",
161                    "require": {
162                        "heroku-sys/php": ">=5.5.0"
163                    },
164                    "replace": [],
165                    "provide": [],
166                    "conflict": []
167                },
168                {
169                    "type": "metapackage",
170                    "name": "guzzlehttp/psr7",
171                    "version": "1.2.3",
172                    "require": {
173                        "heroku-sys/php": ">=5.4.0"
174                    },
175                    "replace": [],
176                    "provide": [],
177                    "conflict": []
178                },
179                {
180                    "type": "metapackage",
181                    "name": "guzzlehttp/ringphp",
182                    "version": "1.1.0",
183                    "require": {
184                        "heroku-sys/php": ">=5.4.0"
185                    },
186                    "replace": [],
187                    "provide": [],
188                    "conflict": []
189                },
190                {
191                    "type": "metapackage",
192                    "name": "guzzlehttp/streams",
193                    "version": "3.0.0",
194                    "require": {
195                        "heroku-sys/php": ">=5.4.0"
196                    },
197                    "replace": [],
198                    "provide": [],
199                    "conflict": []
200                },
201                {
202                    "type": "metapackage",
203                    "name": "hipchat/hipchat-php",
204                    "version": "v1.4",
205                    "require": {
206                        "heroku-sys/php": ">=5.3.0"
207                    },
208                    "replace": [],
209                    "provide": [],
210                    "conflict": []
211                },
212                {
213                    "type": "metapackage",
214                    "name": "kriswallsmith/buzz",
215                    "version": "v0.15",
216                    "require": {
217                        "heroku-sys/php": ">=5.3.0"
218                    },
219                    "replace": [],
220                    "provide": [],
221                    "conflict": []
222                },
223                {
224                    "type": "metapackage",
225                    "name": "league/csv",
226                    "version": "8.0.0",
227                    "require": {
228                        "heroku-sys/ext-mbstring": "*",
229                        "heroku-sys/php": ">=5.5.0"
230                    },
231                    "replace": [],
232                    "provide": [],
233                    "conflict": []
234                },
235                {
236                    "type": "metapackage",
237                    "name": "league/fractal",
238                    "version": "0.13.0",
239                    "require": {
240                        "heroku-sys/php": ">=5.4"
241                    },
242                    "replace": [],
243                    "provide": [],
244                    "conflict": []
245                },
246                {
247                    "type": "metapackage",
248                    "name": "mashape/unirest-php",
249                    "version": "1.2.1",
250                    "require": {
251                        "heroku-sys/ext-curl": "*",
252                        "heroku-sys/ext-json": "*",
253                        "heroku-sys/php": ">=5.3.0"
254                    },
255                    "replace": [],
256                    "provide": [],
257                    "conflict": []
258                },
259                {
260                    "type": "metapackage",
261                    "name": "mtdowling/jmespath.php",
262                    "version": "2.3.0",
263                    "require": {
264                        "heroku-sys/php": ">=5.4.0"
265                    },
266                    "replace": [],
267                    "provide": [],
268                    "conflict": []
269                },
270                {
271                    "type": "metapackage",
272                    "name": "palex/phpstructureddata",
273                    "version": "v2.0.1",
274                    "require": {
275                        "heroku-sys/php": ">=5.3.0"
276                    },
277                    "replace": [],
278                    "provide": [],
279                    "conflict": []
280                },
281                {
282                    "type": "metapackage",
283                    "name": "psr/http-message",
284                    "version": "1.0",
285                    "require": {
286                        "heroku-sys/php": ">=5.3.0"
287                    },
288                    "replace": [],
289                    "provide": [],
290                    "conflict": []
291                },
292                {
293                    "type": "metapackage",
294                    "name": "react/promise",
295                    "version": "v2.2.1",
296                    "require": {
297                        "heroku-sys/php": ">=5.4.0"
298                    },
299                    "replace": [],
300                    "provide": [],
301                    "conflict": []
302                },
303                {
304                    "type": "metapackage",
305                    "name": "rollbar/rollbar",
306                    "version": "v0.15.0",
307                    "require": {
308                        "heroku-sys/ext-curl": "*"
309                    },
310                    "replace": [],
311                    "provide": [],
312                    "conflict": []
313                },
314                {
315                    "type": "metapackage",
316                    "name": "ronanguilloux/isocodes",
317                    "version": "1.2.0",
318                    "require": {
319                        "heroku-sys/ext-bcmath": "*",
320                        "heroku-sys/php": ">=5.4.0"
321                    },
322                    "replace": [],
323                    "provide": [],
324                    "conflict": []
325                },
326                {
327                    "type": "metapackage",
328                    "name": "sendgrid/sendgrid",
329                    "version": "2.1.1",
330                    "require": {
331                        "heroku-sys/php": ">=5.3"
332                    },
333                    "replace": [],
334                    "provide": [],
335                    "conflict": []
336                },
337                {
338                    "type": "metapackage",
339                    "name": "sendgrid/smtpapi",
340                    "version": "0.0.1",
341                    "require": {
342                        "heroku-sys/php": ">=5.3"
343                    },
344                    "replace": [],
345                    "provide": [],
346                    "conflict": []
347                },
348                {
349                    "type": "metapackage",
350                    "name": "symfony/css-selector",
351                    "version": "v2.8.2",
352                    "require": {
353                        "heroku-sys/php": ">=5.3.9"
354                    },
355                    "replace": [],
356                    "provide": [],
357                    "conflict": []
358                },
359                {
360                    "type": "metapackage",
361                    "name": "symfony/http-foundation",
362                    "version": "v2.8.2",
363                    "require": {
364                        "heroku-sys/php": ">=5.3.9"
365                    },
366                    "replace": [],
367                    "provide": [],
368                    "conflict": []
369                },
370                {
371                    "type": "metapackage",
372                    "name": "symfony/polyfill-php54",
373                    "version": "v1.1.0",
374                    "require": {
375                        "heroku-sys/php": ">=5.3.3"
376                    },
377                    "replace": [],
378                    "provide": [],
379                    "conflict": []
380                },
381                {
382                    "type": "metapackage",
383                    "name": "symfony/polyfill-php55",
384                    "version": "v1.1.0",
385                    "require": {
386                        "heroku-sys/php": ">=5.3.3"
387                    },
388                    "replace": [],
389                    "provide": [],
390                    "conflict": []
391                },
392                {
393                    "type": "metapackage",
394                    "name": "thepixeldeveloper/sitemap",
395                    "version": "3.0.0",
396                    "require": {
397                        "heroku-sys/php": ">=5.3.0"
398                    },
399                    "replace": [],
400                    "provide": [],
401                    "conflict": []
402                },
403                {
404                    "type": "metapackage",
405                    "name": "tijsverkoyen/css-to-inline-styles",
406                    "version": "1.5.5",
407                    "require": {
408                        "heroku-sys/php": ">=5.3.0"
409                    },
410                    "replace": [],
411                    "provide": [],
412                    "conflict": []
413                },
414                {
415                    "type": "metapackage",
416                    "name": "yiisoft/yii",
417                    "version": "1.1.17",
418                    "require": {
419                        "heroku-sys/php": ">=5.1.0"
420                    },
421                    "replace": [],
422                    "provide": [],
423                    "conflict": []
424                },
425                {
426                    "type": "metapackage",
427                    "name": "composer.json/composer.lock",
428                    "version": "dev-597511d6d51b96e4a8afeba2c79982e5",
429                    "require": {
430                        "heroku-sys/php": "~5.6.0",
431                        "heroku-sys/ext-newrelic": "*",
432                        "heroku-sys/ext-gd": "*",
433                        "heroku-sys/ext-redis": "*"
434                    },
435                    "replace": [],
436                    "provide": [],
437                    "conflict": []
438                }
439            ]
440        }
441    ],
442    "require": {
443        "composer.json/composer.lock": "dev-597511d6d51b96e4a8afeba2c79982e5",
444        "anthonymartin/geo-location": "v1.0.0",
445        "aws/aws-sdk-php": "3.9.4",
446        "cloudinary/cloudinary_php": "dev-master",
447        "doctrine/annotations": "v1.2.7",
448        "doctrine/cache": "v1.6.0",
449        "doctrine/collections": "v1.3.0",
450        "doctrine/common": "v2.6.1",
451        "doctrine/inflector": "v1.1.0",
452        "doctrine/lexer": "v1.0.1",
453        "geoip/geoip": "v1.16",
454        "giggsey/libphonenumber-for-php": "7.2.5",
455        "guzzlehttp/guzzle": "5.3.0",
456        "guzzlehttp/promises": "1.0.3",
457        "guzzlehttp/psr7": "1.2.3",
458        "guzzlehttp/ringphp": "1.1.0",
459        "guzzlehttp/streams": "3.0.0",
460        "hipchat/hipchat-php": "v1.4",
461        "kriswallsmith/buzz": "v0.15",
462        "league/csv": "8.0.0",
463        "league/fractal": "0.13.0",
464        "mashape/unirest-php": "1.2.1",
465        "mtdowling/jmespath.php": "2.3.0",
466        "palex/phpstructureddata": "v2.0.1",
467        "psr/http-message": "1.0",
468        "react/promise": "v2.2.1",
469        "rollbar/rollbar": "v0.15.0",
470        "ronanguilloux/isocodes": "1.2.0",
471        "sendgrid/sendgrid": "2.1.1",
472        "sendgrid/smtpapi": "0.0.1",
473        "symfony/css-selector": "v2.8.2",
474        "symfony/http-foundation": "v2.8.2",
475        "symfony/polyfill-php54": "v1.1.0",
476        "symfony/polyfill-php55": "v1.1.0",
477        "thepixeldeveloper/sitemap": "3.0.0",
478        "tijsverkoyen/css-to-inline-styles": "1.5.5",
479        "yiisoft/yii": "1.1.17",
480        "heroku-sys/apache": "^2.4.10",
481        "heroku-sys/nginx": "~1.8.0"
482    }
483}';
484
485$res = preg_match('{(?(DEFINE)
486       (?<number>   -? (?= [1-9]|0(?!\d) ) \d+ (\.\d+)? ([eE] [+-]? \d+)? )
487       (?<boolean>   true | false | null )
488       (?<string>    " ([^"\\\\]* | \\\\ ["\\\\bfnrt\/] | \\\\ u [0-9a-f]{4} )* " )
489       (?<array>     \[  (?:  (?&json) \s* (?: , (?&json) \s* )*  )?  \s* \] )
490       (?<pair>      \s* (?&string) \s* : (?&json) \s* )
491       (?<object>    \{  (?:  (?&pair)  (?: , (?&pair)  )*  )?  \s* \} )
492       (?<json>   \s* (?: (?&number) | (?&boolean) | (?&string) | (?&array) | (?&object) ) )
493    )
494^(?P<start>\s*\{\s*(?:(?&string)\s*:\s*(?&json)\s*,\s*)*?)
495(?P<property>'.preg_quote('"require"').'\s*:\s*)(?P<value>(?&json))(?P<end>.*)}sx', $str, $match);
496
497var_dump($res, $match['value'] ?? null, preg_last_error() == PREG_JIT_STACKLIMIT_ERROR);
498?>
499--EXPECT--
500int(1)
501string(1613) "{
502        "composer.json/composer.lock": "dev-597511d6d51b96e4a8afeba2c79982e5",
503        "anthonymartin/geo-location": "v1.0.0",
504        "aws/aws-sdk-php": "3.9.4",
505        "cloudinary/cloudinary_php": "dev-master",
506        "doctrine/annotations": "v1.2.7",
507        "doctrine/cache": "v1.6.0",
508        "doctrine/collections": "v1.3.0",
509        "doctrine/common": "v2.6.1",
510        "doctrine/inflector": "v1.1.0",
511        "doctrine/lexer": "v1.0.1",
512        "geoip/geoip": "v1.16",
513        "giggsey/libphonenumber-for-php": "7.2.5",
514        "guzzlehttp/guzzle": "5.3.0",
515        "guzzlehttp/promises": "1.0.3",
516        "guzzlehttp/psr7": "1.2.3",
517        "guzzlehttp/ringphp": "1.1.0",
518        "guzzlehttp/streams": "3.0.0",
519        "hipchat/hipchat-php": "v1.4",
520        "kriswallsmith/buzz": "v0.15",
521        "league/csv": "8.0.0",
522        "league/fractal": "0.13.0",
523        "mashape/unirest-php": "1.2.1",
524        "mtdowling/jmespath.php": "2.3.0",
525        "palex/phpstructureddata": "v2.0.1",
526        "psr/http-message": "1.0",
527        "react/promise": "v2.2.1",
528        "rollbar/rollbar": "v0.15.0",
529        "ronanguilloux/isocodes": "1.2.0",
530        "sendgrid/sendgrid": "2.1.1",
531        "sendgrid/smtpapi": "0.0.1",
532        "symfony/css-selector": "v2.8.2",
533        "symfony/http-foundation": "v2.8.2",
534        "symfony/polyfill-php54": "v1.1.0",
535        "symfony/polyfill-php55": "v1.1.0",
536        "thepixeldeveloper/sitemap": "3.0.0",
537        "tijsverkoyen/css-to-inline-styles": "1.5.5",
538        "yiisoft/yii": "1.1.17",
539        "heroku-sys/apache": "^2.4.10",
540        "heroku-sys/nginx": "~1.8.0"
541    }"
542bool(false)
543