From:             
Operating system: Linux
PHP version:      Irrelevant
Package:          Unknown/Other Function
Bug Type:         Bug
Bug description:base_convert makes negative numbers positive

Description:
------------
I'd created a fake email code fragment:
  e-mail: foo.<?php echo
base_convert(time(),10,36).".".base_convert(ip2long($_SERVER['REMOTE_ADDR']),10,36)
?>@mydomain.com

However, long2ip(base_convert("cxcapb",36,10)) gave the wrong answer
(should be 209.105.205.209, got 46.150.50.47)

It turns out that base_convert(...,10,36) should have returned -cxcapb
instead of cxcapb, since ip2long("209.105.205.209") = -781595183 and
ip2long("46.150.50.47") = 781595183.

At this point, I'm not sure if there's legions of programs that work around
this bug and would be broken by a fix.

Test script:
---------------
$a=base_convert(-781595183,10,36);
if (base_convert($a,36,10) != -781595183) { echo "fail\n"; } else { echo
"success\!"; }


Expected result:
----------------
success!

Actual result:
--------------
fail

-- 
Edit bug report at https://bugs.php.net/bug.php?id=55393&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55393&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55393&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55393&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55393&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55393&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55393&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55393&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55393&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55393&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55393&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55393&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55393&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55393&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55393&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55393&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55393&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55393&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55393&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55393&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55393&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55393&r=mysqlcfg

Reply via email to