php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36946 base64_decode doesn't work
Submitted: 2006-04-02 10:49 UTC Modified: 2006-04-02 14:13 UTC
From: kirlo at gmx dot de Assigned:
Status: Not a bug Package: *URL Functions
PHP Version: 5.1.2 OS: windows & debian
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kirlo at gmx dot de
New email:
PHP Version: OS:

 

 [2006-04-02 10:49 UTC] kirlo at gmx dot de
Description:
------------
we're encoding some text data with base64 with a small application (not php) on a client pc, then we'll send it to a webserver via POST or GET. the PHP script is fetching POST or GET without any problems but it does not correctly perform the base64_decode operation. we checked our base64 encoded text with other tools (for example http://makcoder.sourceforge.net/demo/base64.php ) and they had no problems!
this system works with the latest php4 version but it does not work with the latest php5 version (on the earlier version it also worked well!). i already tried the latest CVS snapshot but it didn't worked either.

Reproduce code:
---------------
very simple:

echo base64_decode($_POST[base64text]);

Expected result:
----------------
here are three files
the original text:
http://t-man.isr-clan.ath.cx/phpbugreport/original.txt
 
the base64 encoded text (base64 encoding performed by our client application):
http://t-man.isr-clan.ath.cx/phpbugreport/base64encoded.txt

the base64_decode output:
http://t-man.isr-clan.ath.cx/phpbugreport/base64_decode-output.txt

in this case the messed up text is at the end of the text. sometimes the messed up text is starting at the first 2 or 3 lines.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-02 11:51 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-04-02 12:10 UTC] kirlo at gmx dot de
well that's mysterious - this script will work without any problems (put my base64encoded.txt into the scriptdir):
<?php
$fp = fopen ("base64encoded.txt", "r");
$str = fread ($fp, filesize ("base64encoded.txt"));
fclose ($fp);
echo base64_decode($str);
?>

but if you send the string via POST or GET, you'll get this output, where the text ist messed up (copy the content of base64encoded.txt and put it behind yourscript.php?vari= ):
<?php
echo base64_decode($_GET[vari]);
?>
 [2006-04-02 13:08 UTC] tony2001@php.net
What if you use urlencode($data) ? 
 [2006-04-02 13:18 UTC] kirlo at gmx dot de
yes, we've already tried urlencoding as an alternative and urldecode works.
but there's still the base64_decode bug when you send the data via POST or GET.
as i mentioned before, it worked under php4 and the earlier php5 versions.
 [2006-04-02 13:24 UTC] tony2001@php.net
You must use urldecode() on the data you're sending through GET/POST.
No bug here.
 [2006-04-02 13:37 UTC] kirlo at gmx dot de
ok, this time i took the string and used base64 encoding and then i urlencoded that base64 output. i sent this "double encoded" string to the server via POST/GET and there i used this script:
<?php
echo base64_decode(urldecode($_GET[vari]));
?>

and nothing changed. the first lines are ok but then the text is messed up.

(you might think, that the base64 encoding function on my client application does not work properly, but as i mentioned before i've already tested the output with other base64 decoder and they hat no problems)
 [2006-04-02 14:13 UTC] mike@php.net
Don't urldecode $_GET variables and keep in mind taht most servers have an URL lenght limit.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC