xref: /PHP-7.4/ext/pcre/tests/bug79241.phpt (revision b093bd6a)
1--TEST--
2Bug #79241: Segmentation fault on preg_match()
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip json extension missing"; ?>
5--FILE--
6<?php
7
8// if "’" string is used directly without json_decode,
9// the issue does not reproduce
10$text = json_decode('"’"');
11
12$pattern = '/\b/u';
13
14// it has to be exact two calls to preg_match(),
15// with the second call offsetting after the tick symbol
16var_dump(preg_match($pattern, $text, $matches, 0, 0));
17var_dump(preg_match($pattern, $text, $matches, 0, 1));
18var_dump(preg_last_error() == PREG_BAD_UTF8_OFFSET_ERROR);
19
20echo "\n";
21
22$text = "VA\xff"; $text .= "LID";
23var_dump(preg_match($pattern, $text, $matches, 0, 4));
24var_dump(preg_match($pattern, $text, $matches, 0, 0));
25var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR);
26
27?>
28--EXPECT--
29int(0)
30bool(false)
31bool(true)
32
33int(1)
34bool(false)
35bool(true)
36