php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50175 gmp_init() results 0 on given base and number starting with 0x or 0b
Submitted: 2009-11-14 13:46 UTC Modified: 2013-08-06 09:58 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: thomas dot hebinck at digionline dot de Assigned:
Status: Closed Package: GNU MP related
PHP Version: master OS: Ubuntu
Private report: No CVE-ID: None
 [2009-11-14 13:46 UTC] thomas dot hebinck at digionline dot de
Description:
------------
When calling gmp_init() with a *string* starting with 0x or 0b and a given base, 0 is returned (except if the base is 16).

Tested with PHP 5.2.3, PHP 5.3 and PHP 5.3-200911141130.


Reproduce code:
---------------
for($base=2;$base<=36;$base++) {
  echo '<br>'.$base.': ';
  for($i=1;$i<$base;$i++) {
    $c=($i<=9?$i:chr($i-10+ord('a')));
    $s='0'.$c.$c;
    echo gmp_strval(gmp_init($s,$base),$base) . ' ';
  }
}

Expected result:
----------------
2: 11 
3: 11 22 
4: 11 22 33 
5: 11 22 33 44 
6: 11 22 33 44 55 
7: 11 22 33 44 55 66 
8: 11 22 33 44 55 66 77 
9: 11 22 33 44 55 66 77 88 
10: 11 22 33 44 55 66 77 88 99 
11: 11 22 33 44 55 66 77 88 99 aa 
12: 11 22 33 44 55 66 77 88 99 aa bb 
13: 11 22 33 44 55 66 77 88 99 aa bb cc 
14: 11 22 33 44 55 66 77 88 99 aa bb cc dd 
15: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee 
16: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 
17: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg 
18: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh 
19: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii 
20: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj 
21: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk 
22: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll 
23: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm 
24: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn 
25: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo 
26: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp 
27: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq 
28: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr 
29: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss 
30: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt 
31: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu 
32: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv 
33: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww 
34: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx 
35: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy 
36: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 


Actual result:
--------------
2: 11 
3: 11 22 
4: 11 22 33 
5: 11 22 33 44 
6: 11 22 33 44 55 
7: 11 22 33 44 55 66 
8: 11 22 33 44 55 66 77 
9: 11 22 33 44 55 66 77 88 
10: 11 22 33 44 55 66 77 88 99 
11: 11 22 33 44 55 66 77 88 99 aa 
12: 11 22 33 44 55 66 77 88 99 aa 0 
13: 11 22 33 44 55 66 77 88 99 aa 0 cc 
14: 11 22 33 44 55 66 77 88 99 aa 0 cc dd 
15: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee 
16: 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 
17: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg 
18: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh 
19: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii 
20: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj 
21: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk 
22: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll 
23: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm 
24: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn 
25: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo 
26: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp 
27: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq 
28: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr 
29: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss 
30: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt 
31: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu 
32: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv 
33: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww 
34: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww 0 
35: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww 0 yy 
36: 11 22 33 44 55 66 77 88 99 aa 0 cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww 0 yy zz 


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-29 22:39 UTC] karl dot debisschop at pearson dot com
in php 5.3.6, the issue seems to be resolve with respect to "0x"

> php -r '$v = gmp_init("0x83", 36); print("$v\n");'
Resource id #4
> php -r '$v = gmp_init("0b83", 36); print("$v\n");'

> php -r '$v = gmp_init("0b83", 16); print("$v\n");'
Resource id #4
> php -r '$v = gmp_init("b83", 36); print("$v\n");'
Resource id #4

Also, the actual return value from gmp_init() is FALSE:

> php -r '$v = gmp_init("0b83", 36); if ($v === FALSE) print("false\n");'
false
 [2013-08-06 09:58 UTC] yohgaki@php.net
-PHP Version: 5.3.0 +PHP Version: master
 [2014-09-02 17:06 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=834daa455bc9c8cde178c6978dcb548119b038e8
Log: Fixed bug #50175
 [2014-09-02 17:06 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2014-09-02 17:08 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=834daa455bc9c8cde178c6978dcb548119b038e8
Log: Fixed bug #50175
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC