php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75781 substr_count incorrect result
Submitted: 2018-01-08 22:52 UTC Modified: -
From: gajowy at agzeta dot pl Assigned:
Status: Closed Package: Strings related
PHP Version: 7.1.13 OS: Windows 10 64bit
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: gajowy at agzeta dot pl
New email:
PHP Version: OS:

 

 [2018-01-08 22:52 UTC] gajowy at agzeta dot pl
Description:
------------
For "big" string the substr_count function returns incorrect result.
Memory limit in PHP set to 30GB.
Seems it works incorrect for strings>4GB.

Test script:
---------------
<?php
$size=9*1024*1024*1024;		// 9GB
$buf=str_repeat(chr(0),$size);
for( $i=0; $i<$size; $i++ )
	if( $i%3==0 )
		$buf{$i}=chr(255);
$cnt=substr_count($buf,chr(255));
var_dump($cnt);
?>

Expected result:
----------------
int(3221225472)

Actual result:
--------------
int(-1073741824)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-09 08:23 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6da44fefb2065e28c6329f45b40c5611f86f4bf3
Log: Fixed bug #75781 (substr_count incorrect result)
 [2018-01-09 08:23 UTC] laruence@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC