Bug #68068 [Com]: base64_encode should take byte streams and a length

From: Date: Mon, 22 Sep 2014 12:22:17 +0000
Subject: Bug #68068 [Com]: base64_encode should take byte streams and a length
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187648@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68068&edit=1

 ID:                 68068
 Comment by:         wzis at hotmail dot com
 Reported by:        wzis at hotmail dot com
 Summary:            base64_encode should take byte streams and a length
 Status:             Not a bug
 Type:               Bug
 Package:            hash related
 Operating System:   UNIX/Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Thanks. You are correct, my mistake: I assumed the PHP also uses null as the end of string, and
didn't use strlen to check.


Previous Comments:
------------------------------------------------------------------------
[2014-09-22 05:07:07] rasmus@php.net

String lengths in PHP are not determined by a null character. You can easily test this for yourself.
If they were, then this should print the same base64 encoded string twice:

echo base64_encode("abc\0def");
echo "\n";
echo base64_encode("abc");

It doesn't, of course.

------------------------------------------------------------------------
[2014-09-22 02:01:50] wzis at hotmail dot com

Description:
------------
---
From manual page: http://www.php.net/function.base64-encode
---
base64_encode now only takes one str argument, that will make conversion of a byte stream with \0 in
it fail, so can't convert arbitrary byte stream properly.

Test script:
---------------
$randv=shell_exec("dd if=/dev/urandom bs=1 count=6 2>/dev/null");
$salt="\$1\$".base64_encode($randv);

Expected result:
----------------
$salt="\$1\$".base64_encode($randv, 6);

Actual result:
--------------
depends on what we get from the /dev/urandom, the $salt could be shorter than 8 characters as it
supposed to be.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68068&edit=1


Thread (3 messages)

« previous php.bugs (#187648) next »