php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64395 Wrong result
Submitted: 2013-03-08 19:54 UTC Modified: 2013-06-19 12:15 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 2 (0.0%)
From: abc905 at mail dot ru Assigned:
Status: Wont fix Package: Network related
PHP Version: 5.4.13 OS: Windows 7 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: abc905 at mail dot ru
New email:
PHP Version: OS:

 

 [2013-03-08 19:54 UTC] abc905 at mail dot ru
Description:
------------
Hello,
It seems ip2long function returns wrong result   
1.1.9.9 instead of 1.1.11.11 when convert ip address like '1.1.011.011'

Thank you,
Alexander

---
From manual page: http://www.php.net/function.long2ip
---


Test script:
---------------
$ip = '1.1.011.011';
$ip_long = sprintf("%u", ip2long($ip));
print long2ip($ip_long);



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-17 02:39 UTC] pete at petermcdonald dot co dot uk
I have tried to reproduce on php 5.4.11 (zend server install) using code specified 
but output is expected 1.1.11.11.
 [2013-03-21 16:11 UTC] abc905 at mail dot ru
Unfortunatly my output is wrong

PHP. Ver.  5.4.11 (Open Server Win7 x64) and 5.4.9 (Windows Installer install)
Output:    
1.1.011.011 -> 1.1.9.9
1.1.071.071 -> 1.1.57.57
1.1.081.081 -> 0.0.0.0
Looks like long2ip() converts segments with leading zero as octal.
 [2013-03-28 15:48 UTC] abc905 at mail dot ru
-PHP Version: 5.4.12 +PHP Version: 5.4.13
 [2013-03-28 15:48 UTC] abc905 at mail dot ru
PHP. Ver.  5.4.13 (Open Server Win7 x64)
Output:    
1.1.011.011 -> 1.1.9.9
1.1.071.071 -> 1.1.57.57
1.1.081.081 -> 0.0.0.0
Looks like long2ip() converts segments with leading zero as octal.
 [2013-04-21 12:37 UTC] sjon at hortensius dot net
Php interprets numbers with leading zeros as octal [1]. Octal 011 = Decimal 9. 
Also, I think this is not a valid IP address notation.

This is fixed in newer PHP versions, where this format is rejected and false is 
returned; see http://3v4l.org/EBD9k

1. http://php.net/manual/en/language.types.integer.php
 [2013-06-19 12:15 UTC] ab@php.net
-Status: Open +Status: Wont fix
 [2013-06-19 12:15 UTC] ab@php.net
This won't fix in 5.4 - the native inet_pton platform implementation is available starting with windows vista 
http://msdn.microsoft.com/en-us/library/windows/desktop/cc805844(v=vs.85).aspx , in 5.4 however windows xp support is guaranteed.

In 5.5 the sdk implementation is used, which validates this issue as fixed there. Prior to that PHP own inet_pton implementation is used, 
which isn't perfect. However the case you brought is just one of many more complicated, imagine one would use a hex notation for 
segments including upper and lower letter case. Parsing this is much more complicated and facing the fact it's fixed in 5.5 I'm really not 
sure it's worth to touch 5.4.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jun 25 10:01:23 2021 UTC