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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jjj17 at yandex dot ru
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 09:01:27 2025 UTC