Bug #64109 [Opn]: incorrect use of abs() in array_pad()

From: Date: Sun, 17 Feb 2013 03:46:28 +0000
Subject: Bug #64109 [Opn]: incorrect use of abs() in array_pad()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-176662@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64109&edit=1

 ID:                 64109
 Updated by:         laruence@php.net
 Reported by:        xi dot wang at gmail dot com
 Summary:            incorrect use of abs() in array_pad()
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 PHP Version:        master-Git-2013-01-30 (Git)
-Assigned To:        
+Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

actually, there are some other issues,  like use abs on a long number.  

I am not sure whether this is a critical bug, but will try to fix it only for 5.4+


Previous Comments:
------------------------------------------------------------------------
[2013-01-30 21:33:10] xi dot wang at gmail dot com

Description:
------------
Using `abs(pad_size) < 0' to catch the LONG_MIN case invokes undefined behavior in 
C.  gcc simply assumes abs(pad_size) must be non-negative and discards the check.

Test script:
---------------
<?php
// This is for 64-bit systems.
$input = array(12, 10, 9);
$input = array_pad($input, -9223372036854775808, 0);
var_dump($input);
?>

Expected result:
----------------
Warning: array_pad(): You may only pad up to 1048576 elements at a time in t.php 
on line 3
bool(false)

Actual result:
--------------
array(3) {
  [0]=>
  int(12)
  [1]=>
  int(10)
  [2]=>
  int(9)
}


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64109&edit=1


Thread (4 messages)

« previous php.bugs (#176662) next »