From:             rob at neovidamedia dot com
Operating system: Windows 7
PHP version:      Irrelevant
Package:          *Encryption and hash functions
Bug Type:         Bug
Bug description:Extra characters added to base64_decode() output

Description:
------------
---
>From manual page: http://www.php.net/function.base64-decode
---

Run this code, and notice the output for 'Decoded' -- it looks the same as

'Original', but it is not.  Select it (the result), copy it, and paste it
into 
notepad or something, and you will see a bonus character at the end.

It seems to be related to the string length of $a, and the fact that it
contains 
a 
number at its end, but I could be wrong.  I ran about one hundred different

scenario tests, and got some funky results.

PS - I am running PHP 5.2.17, but that is what my host offers.  Don't think
I 
can upgrade on my own ...

Test script:
---------------
$a = "Proteussing88";

function randLetter()
    {
    $int = rand(0,61);
    $a_z =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    $rand_letter = $a_z[$int];
    return $rand_letter;
    }
$pass = randLetter() . base64_encode($a) . randLetter() . randLetter() .
randLetter();

$db_pass = base64_decode(substr($pass, 1, (strlen($pass) - 2)));
$final = substr($db_pass, 0, (strlen($db_pass) - 1));

echo 'Original: ' . $a . '<br />Encoded: ' . $pass . '<br />Decoded: ' .
$final;

Expected result:
----------------
The visual result is fine, but in the background a special character is
being 
added to the final string variable.

Actual result:
--------------
The final string variable looks right, but only in a browser.  Paste it
into 
notepad or any other text editor, and you get an unexpected special
character at 
its end.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64162&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64162&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64162&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64162&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64162&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64162&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64162&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64162&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64162&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64162&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64162&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64162&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64162&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64162&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64162&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64162&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64162&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64162&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64162&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64162&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64162&r=mysqlcfg

Reply via email to