Bug #79241 [Ana->Csd]: Segmentation fault on preg_match()

From: Date: Tue, 11 Feb 2020 11:19:26 +0000
Subject: Bug #79241 [Ana->Csd]: Segmentation fault on preg_match()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225490@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79241&edit=1 ID: 79241 Updated by: cmb@php.net Reported by: ivan dot voskoboinyk at gmail dot com Summary: Segmentation fault on preg_match() -Status: Analyzed +Status: Closed Type: Bug Package: PCRE related Operating System: Ubuntu 19.04 PHP Version: 7.4.2 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Fixed with <http://git.php.net/?p=php-src.git;a=commit;h=c9e78e6d338cc46dcadb39b3e2df119fa969e72b>. Previous Comments: ------------------------------------------------------------------------ [2020-02-07 15:19:44] nikic@php.net Pretty sure this is due to the VALID_UTF8 optimization. We remember that the string is valid UTF-8, but we also need to verify that the offset is at a valid character boundary. ------------------------------------------------------------------------ [2020-02-07 15:10:41] ivan dot voskoboinyk at gmail dot com Description: ------------ We had this bug on our production server happening on matching Regex on a unicode string decoded from JSON. I've taken the exact production code and removed everything that is not necessary for demonstrating the problem. Removing any other part from the snippet bellow fixes the crash. It seems the issue only appeared in PHP 7.4: https://3v4l.org/DqL76 Test script: --------------- // if "’" string is used directly without json_decode, // the issue does not reproduce $text = json_decode('"’"'); $pattern = '/\b/u'; // it has to be exact two calls to preg_match(), // with the second call offsetting after the tick symbol preg_match($pattern, $text, $matches, 0, 0); preg_match($pattern, $text, $matches, 0, 1); echo 'OK'; Expected result: ---------------- "OK" is output Actual result: -------------- Segmentation fault (core dumped) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79241&edit=1

« previous php.bugs (#225490) next »