php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61863 bitwise operation make overflow
Submitted: 2012-04-27 06:36 UTC Modified: 2015-06-07 16:28 UTC
From: admin at todayis dot kr Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.0 OS: Windows/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at todayis dot kr
New email:
PHP Version: OS:

 

 [2012-04-27 06:36 UTC] admin at todayis dot kr
Description:
------------
if i use bitwise operation then variable type doesn't changed float or other type.
stay in int

Test script:
---------------
$value = "abcdefg";
for($i=0,$h=0;$i <strlen($value);$i++) {
	$h = ($h << 10) + ord($value[$i]);
	echo $h."\n";
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-27 07:04 UTC] admin at todayis dot kr
.
 [2012-04-27 07:04 UTC] admin at todayis dot kr
-Summary: bitwise operation make buffer overflow +Summary: bitwise operation make overflow -PHP Version: 5.4Git-2012-04-27 (Git) +PHP Version: 5.4.0
 [2015-06-07 16:28 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: Apache2 related +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2015-06-07 16:28 UTC] cmb@php.net
This behavior is by design, and it's clearly documented[1]:

| Shifting integers by values greater than or equal to the system
| long integer width results in undefined behavior. In other
| words, don't shift more than 31 bits on a 32-bit system, and
| don't shift more than 63 bits on a 64-bit system.
|
| Use functions from the gmp extension for bitwise manipulation on
| numbers beyond PHP_INT_MAX.

[1] <http://php.net/manual/en/language.operators.bitwise.php>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 17:01:30 2025 UTC