php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55393 base_convert makes negative numbers positive
Submitted: 2011-08-10 18:20 UTC Modified: -
Votes:4
Avg. Score:3.0 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: phpbugs at ch dot pkts dot ca Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-08-10 18:20 UTC] phpbugs at ch dot pkts dot ca
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 07:02:14 2014 UTC