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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-15 10:41 UTC] andrei@php.net
Fixed in CVS - thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 23 17:01:36 2025 UTC