php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77923 preg_* function cannot get correct result
Submitted: 2019-04-19 11:23 UTC Modified: 2019-04-20 05:52 UTC
From: 2317216477 at qq dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 7.2.18RC1 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 2317216477 at qq dot com
New email:
PHP Version: OS:

 

 [2019-04-19 11:23 UTC] 2317216477 at qq dot com
Description:
------------
preg_* function cannot get correct result in php7.0~7.2 sometimes

the test string is too long so I put a test script on my github page(https://github.com/icy2003/php/blob/master/samples/php7preg_bug.php)

you can test this script on this website:https://3v4l.org/,or you can install php 7.0~7.2 in local environment

Test script:
---------------
https://github.com/icy2003/php/blob/master/samples/php7preg_bug.php

Expected result:
----------------
my pattern expected some results but in php7.0~7.2 it will be empty array!!

you can use "ini_set" and set "pcre.jit" to 0 before preg_* functions to fix the problem


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-19 11:33 UTC] 2317216477 at qq dot com
You can use "ini_set" and set "pcre.jit" to 0 before preg_* functions to fix the problem
I don't know why it happens and hope someone can fix it basically
 [2019-04-20 05:52 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-04-20 05:52 UTC] requinix@php.net
Your regular expression is too inefficient to be used with JIT mode on such a large input. PCRE (not PHP) is aborting executing because it ran out of stack space - preg_last_error() = PREG_JIT_STACKLIMIT_ERROR (6).

Disabling JIT for that regex is a workaround. Fixing the regex is better.

But personally I would consider using SimpleXML to find the <w:p> elements, scan for your ${var} or ${/var} tokens, then... I don't know what you want to do from there.
 [2019-04-22 01:56 UTC] 2317216477 at qq dot com
I checked https://www.php.net/manual/zh/pcre.constants.php and I found Robert(a user added a note)said the same problem, I think it's still a problem for php7.0 to 7.2, for example,
this is my regular func:
preg_f()
and this is my pseudo code:
preg_f()
error = preg_last_error()
if(error){
preg_f()
}
Only if I re-match can I get the correct result, I think it is not reasonable because the logic:"I don't know I will be right or not until I checked preg_last_error()", that is ... I don't know, maybe stupid.
Maybe php7.0 to 7.2 should handle it itself, or just throw a fatal error so a user know the expression is correct or not in a certain way directly!
In a word, it returns a different result with php5 or php7.3+, it makes me puzzled
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC