php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53566 base64_decode gives wrong result when added a \0 octet to the unencoded data
Submitted: 2010-12-17 21:58 UTC Modified: 2010-12-18 16:07 UTC
From: jjj17 at yandex dot ru Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.16 OS:
Private report: No CVE-ID: None
 [2010-12-17 21:58 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-18 16:07 UTC] cataphract@php.net
-Summary: php 5.2.14 +Summary: base64_decode gives wrong result when added a \0 octet to the unencoded data -Status: Open +Status: Bogus
 [2010-12-18 16:07 UTC] cataphract@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC