Bug #53566 [Opn->Bgs]: base64_decode gives wrong result when added a \0 octet to the unencoded data
| From: | cataphract@php.net | Date: | Sat, 18 Dec 2010 15:07:44 +0000 |
| Subject: | Bug #53566 [Opn->Bgs]: base64_decode gives wrong result when added a \0 octet to the unencoded data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157076@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53566&edit=1
ID: 53566
Updated by: cataphract@php.net
Reported by: jjj17 at yandex dot ru
-Summary: php 5.2.14
+Summary: base64_decode gives wrong result when added a \0
octet to the unencoded data
-Status: Open
+Status: Bogus
Type: Bug
Package: Unknown/Other Function
PHP Version: 5.2.16
Block user comment: N
Private report: N
New Comment:
You are corrupting the encoding data, namely adding an octet that isn't
allowed in base 64, why would you expect the correct result?...
Furthermore, basse 64 encoded strings do not have to end in the padding
character.
Note you can use base64_decode($aa.'\\0', true); to force the function
to fail when the input is invalid.
Previous Comments:
------------------------------------------------------------------------
[2010-12-17 21:58:24] jjj17 at yandex dot ru
Description:
------------
---
From manual page: http://www.php.net/function.base64-decode#Return
Values
---
If a string to decode has wrong bytes at the end of the string, which
normally ends with "=", then base64_decode() returns a wrong result of
decode.
Test script:
---------------
<?php
$a = "qwertyui";
$aa = base64_encode($a);
echo base64_decode($aa.'\\0');
?>
Expected result:
----------------
qwertyui
Actual result:
--------------
qwertyui4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53566&edit=1