Bug #14173: preg_match incorrectly parses data with binary zero

From: Date: Thu, 22 Nov 2001 11:23:45 +0000
Subject: Bug #14173: preg_match incorrectly parses data with binary zero
Groups: php.dev 
Request: Send a blank email to php-dev+get-71372@lists.php.net to get a copy of this message
From: frog@enlight.ru Operating system: Win98 PHP version: 4.0.6 PHP Bug Type: PCRE related Bug description: preg_match incorrectly parses data with binary zero $data = "abc\0\0de"; # \0, \x00 - never mind preg_match('/ab(.{4})e/s', $data, $res); echo(bin2hex($data)); # 61626300006465 echo(bin2hex($res[0])); # 616263 echo(bin2hex($res[1])); # 63 PHP4.0.6/Win32 (binary distr.) From PHP PCRE docs: -------------- 4. Though binary zero characters are supported in the subject string, they are not allowed in a pattern string because it is passed as a normal C string, terminated by zero. The escape sequence "\0" can be used in the pattern to represent a binary zero. ----------- From original PCRE docs (http://www.pcre.org/man.txt): -------- The subject string is passed as a pointer in subject, a length in length, and a starting offset in startoffset. Unlike the pattern string, the subject may contain binary zero characters. When the starting offset is zero, the search for a match starts at the beginning of the subject, and this is by far the most common case. --------- by the way, it seems that preg_replace() works correctly. Problems with preg_match() please report if i'm wrong and it isn't a bug. -- Edit bug report at: http://bugs.php.net/?id=14173&edit=1

« previous php.dev (#71372) next »