php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14807 base_convert() crashes with > 1500 digits
Submitted: 2002-01-02 13:39 UTC Modified: 2002-06-17 20:04 UTC
From: amnuts at talker dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 4.3.0-dev OS: Linux
Private report: No CVE-ID: None
 [2002-01-02 13:39 UTC] amnuts at talker dot com
Running the following always causes a core dump:

<?php

$arr = array (
        1 => array ("0","0","0","0","0"),
        2 => array ("0","0","0","0","0"),
        3 => array ("0","0","0","0","0"),
        4 => array ("0","0","0","0","0"),
        5 => array ("0","0","0","0","0")
        );

print_r($arr);
echo "<br>\n\n<br>\n\n";
$str = serialize($arr);
echo "serialized<br>\n", $str, "<br><br>\n\n";

function hex2bin($data) {
    $len = strlen($data);
    return pack("H" . $len, $data);
}

$enc = urlencode($str);
echo "urlencoded<br>", $enc, "<br><br>\n\n";
$gzd = gzcompress($enc);
//echo "gzcompressed (urlencoded)<br>", $gzd, "<br><br>\n\n";
$b64 = base64_encode($gzd);
echo "base64_encoded<br>", $b64, "<br><br>\n\n";
$b2h = bin2hex($enc);
echo "bin2hex (urlencoded)<br>", $b2h, "<br><br>\n\n";
$binary = base_convert($b2h, 16, 2);
echo $binary, "<br><br>\n\n";
$conv = base_convert($binary, 2, 16);
echo $conv, "<br><br>\n\n";
$h2b = hex2bin($conv);
echo $h2b, "<br><br>\n\n";
$md = md5($str);
echo "md5<br>", $md, "<br><br>\n";

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-02 13:46 UTC] jan@php.net
at least for me it doesn't (FreeBSD 4.4 PHP 4.1.0)
can you provide more Information about you environmation (OS, configure options e.g.) ?

 [2002-01-02 14:11 UTC] amnuts at talker dot com
I am using it in CGI mode, and this is some info that might be useful to you:

bash$ cat /proc/version
Linux version 2.2.20 (gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) #1 SMP Fri Nov 9 09:25:22 EST 2001

phpinfo()

PHP Version 4.1.0
System Linux <host name removed> 2.2.20 #1 SMP Fri Nov 9 09:25:22 EST 2001 i686 unknown
Build DateDec 24 2001
Configure Command './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--with-curl' '--with-swf=/usr/local/flash' '--enable-ftp' '--with-gd=../gd-1.8.4' '--with-jpeg-dir=/usr/local' '--with-xpm-dir=/usr/X11R6' '--with-png-dir=/usr' '--with-imap=../imap-2001.BETA.SNAP-0105220031' '--with-ming=../ming-0.1.1' '--enable-magic-quotes' '--with-mysql' '--enable-safe-mode' '--enable-track-vars' '--with-ttf' '--enable-versioning' '--with-zlib'
Server API CGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/Zend/etc/php.ini
ZEND_DEBUG disabled
Thread Safety disabled


If you need anything else, just let me know.
 [2002-01-03 03:43 UTC] thies@php.net
your testcase can be reduced to:
<?php
$data = 
"612533413525334125374269253341312533426125334135253341253742692533413025334273253341312533412532323025323225334269253341312533427325334131253341253232302532322533426925334132253342732533413125334125323230253232253342692533413325334273253341312533412532323025323225334269253341342533427325334131253341253232302532322533422537446925334132253342612533413525334125374269253341302533427325334131253341253232302532322533426925334131253342732533413125334125323230253232253342692533413225334273253341312533412532323025323225334269253341332533427325334131253341253232302532322533426925334134253342732533413125334125323230253232253342253744692533413325334261253341352533412537426925334130253342732533413125334125323230253232253342692533413125334273253341312533412532323025323225334269253341322533427325334131253341253232302532322533426925334133253342732533413125334125323230253232253342692533413425334273253341312533412532323025323225334225374469253341342533426125334135253341253742692533413025334273253341312533412532323025323225334269253341312533427325334131253341253232302532322533426925334132253342732533413125334125323230253232253342692533413325334273253341312533412532323025323225334269253341342533427325334131253341253232302532322533422537446925334135253342612533413525334125374269253341302533427325334131253341253232302532322533426925334131253342732533413125334125323230253232253342692533413225334273253341312533412532323025323225334269253341332533427325334131253341253232302532322533426925334134253342732533413125334125323230253232253342253744253744";
$binary = base_convert($data, 16, 2);
?>

you are trying to base_convert a number with > 1500 digits. this is not going to work! but it shouln't crash, 
i agree. (no time to fix it right now)



 [2002-03-30 13:44 UTC] mss at medecom dot com
Another test case which makes base_convert dump core is this:

<?php
$x=base_convert ("2f0f336509c9a3d0f29e4281321d496f", 16, 36);
echo $x;
echo Done;
?>

I have not experienced this problem under SuSE 7.2 but under the following:


Mandrake 8.2
Linux p700 2.4.18-6mdk #1 Fri Mar 15 02:59:08 CET 2002 i686 unknown

apache-1.3.23-4mdk
apache-common-1.3.23-4mdk
apache-modules-1.3.23-4mdk
mod_php-4.1.2-1mdk
php-4.1.2-1mdk
php-common-4.1.2-1mdk
 [2002-06-17 19:13 UTC] sniper@php.net
Reproduced with latest CVS HEAD.

 [2002-06-17 20:04 UTC] edink@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Sep 17 00:01:28 2024 UTC