php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14173 preg_match incorrectly parses data with binary zero
Submitted: 2001-11-22 06:23 UTC Modified: 2002-01-15 10:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: frog at enlight dot ru Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.0.6 OS: Win98
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: frog at enlight dot ru
New email:
PHP Version: OS:

 

 [2001-11-22 06:23 UTC] frog at enlight dot ru
$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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-15 10:41 UTC] andrei@php.net
Fixed in CVS - thanks.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 15 16:01:26 2018 UTC