PHP :: Bug #76127 :: preg_split does not raise an error on invalid UTF-8
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76127 preg_split does not raise an error on invalid UTF-8
Submitted: 2018-03-21 13:36 UTC Modified: 2018-03-21 15:32 UTC
From: graefrath at femu dot rwth-aachen dot de Assigned:
Status: Verified Package: PCRE related
PHP Version: 5.6.34 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-03-21 13:36 UTC] graefrath at femu dot rwth-aachen dot de
Description:
------------
preg_match and preg_replace return false and set the last error to PREG_BAD_UTF8_ERROR when the u modifier is specified and the subject is invalid UTF-8. However, preg_split does not behave consistently in this regard.

Test script:
---------------
var_dump(preg_split("/a/u", "a\xff"));

Expected result:
----------------
preg_split should return false and set the last error PREG_BAD_UTF8_ERROR just like the other preg_ functions.

Actual result:
--------------
preg_split returns an array with the subject string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-21 15:32 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-03-21 15:32 UTC] cmb@php.net
Confirmed: <https://3v4l.org/1WYQE>.

The problem is that although the error is detected[1],
php_pcre_split_impl() happily proceeds, while
php_pcre_match_impl() checks for an error in the end, and returns
FALSE in that case[2].

[1] <https://github.com/php/php-src/blob/PHP-7.2.4/ext/pcre/php_pcre.c#L2369>
[2] <https://github.com/php/php-src/blob/PHP-7.2.4/ext/pcre/php_pcre.c#L1134-L1139>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sat Aug 18 12:01:26 2018 UTC