Bug 91042

Summary: PCRE functions in php incorrectly process binary data containing binary zeros
Product: [Retired] Red Hat Linux Reporter: Need Real Name <bearl>
Component: phpAssignee: Joe Orton <jorton>
Status: CLOSED WONTFIX QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.3   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-01-25 16:47:43 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Need Real Name 2003-05-16 18:58:57 UTC
Description of problem:
PCRE-functions do not correctly process binary data containing binary zeros.
Results are being truncated at the first binary zero in the resulting string.

For example, pattern "/.*/s" should match all incoming strings, but it matches
only part of the string from the beginning to the first binary zero. This
problem seems to be common in preg_match and preg_match_all functions.

Version-Release number of selected component (if applicable):
php-4.1.2-7.3.6

How reproducible:
Consistently

Steps to Reproduce:
The following short script illustrates the problem. It reads a .jpg and .pdf
file, and outputs the real length of each file and the length as parsed by the
"preg_match" function.  On a default RH7.3 system the parsed lengths will be
much smaller, but using php compiled from source this works as expected and the
parsed length will match the real length.

<?
$f=fopen('test.pdf', 'rb');
$data=fread($f, filesize('test.pdf'));
fclose($f);
preg_match('/.*/s', $data, $matches);

echo 'PDF<br>
';
echo 'Source data length: ' . strlen($data) . '<br>
';
#print_r($matches);
echo 'Parsed data length: ' . strlen($matches[0]) . '<br>
';

$f=fopen('test.jpg', 'rb');
$data=fread($f, filesize('test.jpg'));
fclose($f);
preg_match('/.*/s', $data, $matches);

echo 'JPEG<br>
';
echo 'Source data length: ' . strlen($data) . '<br>
';
#print_r($matches);
echo 'Parsed data length: ' . strlen($matches[0]) . '<br>
';
?>

    
Actual results:
pcre function incorrectly processes binary data.

Expected results:
Correctly processs that binary data. :)

Additional info:
The behavior appears identical to the bug described in the link below. The php
site says it was fixed in January of 2002.

http://bugs.php.net/bug.php?id=14173

Comment 1 Joe Orton 2005-01-25 16:47:43 UTC
Thanks for the report.  This is a mass bug update; since this release
of Red Hat Linux is no longer supported, please either:

a) try and reproduce the bug with a supported version of Red Hat
Enterprise Linux or Fedora Core, and re-open this bug as appropriate
after changing the Product field, or,

b) if relevant, try and reproduce this bug using the current version
of the upstream package, and report the bug upstream.

c) report the bug to the Fedora Legacy project who may wish to
continue maintenance of this package.