php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47774 Integer Overflow
Submitted: 2009-03-25 14:28 UTC Modified: 2009-03-26 06:36 UTC
From: vivekanandan8 at yahoo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2CVS-2009-03-25 (snap) OS: Debian
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: vivekanandan8 at yahoo dot com
New email:
PHP Version: OS:

 

 [2009-03-25 14:28 UTC] vivekanandan8 at yahoo dot com
Description:
------------
Generally when integer number exceed(overflows), it is converted to float,But for the number -2147483648 the Integer can hold, but converted to float.   

Reproduce code:
---------------
<?
$vValue	=	(int)-2147483648;
var_dump($vValue);
$vValue	= -2147483648;
var_dump($vValue);
?>

Expected result:
----------------
int(-2147483648) int(-2147483648) 

Actual result:
--------------
int(-2147483648) float(-2147483648) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-25 16:15 UTC] mattwil@php.net
This is the expected behavior. Happens because it's not parsed as a single negative number, but a positive number (and 2147483648 needs to be a float) that is then negated afterwards. So it's treated more like -(2147483648). Hope that helps explain what's going on. :-)
 [2009-03-26 06:36 UTC] vivekanandan8 at yahoo dot com
Hi,
   Thanks for your information.but when the overflow occurs at the 
runtime, then also the data type conversion does not change.
Ex: 
<?
$vValue = -2147483649;
var_dump($vValue); //output: float(-2147483649) 
$vValue++;
var_dump($vValue);//output: float(-2147483648) 
$vValue++;
var_dump($vValue);//output: float(-2147483647)
?>
Initially $vValue is double , but even later execution it is not converted to integer when it can hold values. 

   when the overflow occurs we convert  from long to double but i fell it is not done from double to long.
Hence in the function increment_function(zend_operators.c)
we have to add the validation as follows 
case IS_DOUBLE:  
 if(op1->value.dval == LONG_MIN) {   
  op1->value.lval = (long) op1->value.dval+1;
  op1->type = IS_LONG; 
 }else{
   op1->value.dval = op1->value.dval + 1;
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 19:01:36 2025 UTC