php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77009 base64_decode different behavior in php 5.6 and 7.2
Submitted: 2018-10-12 14:24 UTC Modified: 2018-10-14 21:40 UTC
Votes:3
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: klewi1983 at wp dot pl Assigned:
Status: Re-Opened Package: *URL Functions
PHP Version: Irrelevant OS: Windows 7 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-10-12 14:24 UTC] klewi1983 at wp dot pl
Description:
------------
XAMPP 5.6.31 32bit:
PHP 5.6.31 (cli) (built: Jul  5 2017 22:25:43)

XAMPP 7.2.10, both 32 bit:
PHP 7.2.10 (cli) (built: Sep 13 2018 01:01:10) ( ZTS MSVC15 (Visual C++ 2017) x86 )


My test file (test.bin) size is 123 KB.
How can I attach it to the bug?

Test script:
---------------
var_dump(base64_decode(file_get_contents("test.bin")));

Expected result:
----------------
string(0) ""

Actual result:
--------------
result in PHP 5.6.31:
string(0) ""

result in PHP 7.2.10:
string(22534) "Yt       yeN)O?←┬ÁuAŞČ7L...............

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-12 14:56 UTC] cmb@php.net
> My test file (test.bin) size is 123 KB.
> How can I attach it to the bug?

Please make the file available for download.
 [2018-10-13 09:40 UTC] klewi1983 at wp dot pl
My example file link:
https://drive.google.com/open?id=1gJXkA3iJO-a4Sw1Cy9GdE1SITGxWe2Va
 [2018-10-14 11:03 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-10-14 11:03 UTC] cmb@php.net
Thanks!

The “new” behavior is correct according to the documentation;
since $strict is FALSE, invalid Base64 characters are silently
discarded.  The following script confirms this:

    <?php
    $data = file_get_contents("test.bin");
    $stripped = preg_replace('/[^A-Za-z0-9+\/]/', '', $data);
    var_dump(base64_decode($data) === base64_decode($stripped, true));
 [2018-10-14 19:51 UTC] klewi1983 at wp dot pl
Thanks for the explanation, however, it would be useful to mention the difference in the operation of the function in the document describing migration from php 5.6 to 7.0, or 7.2 to 7.3 ;-)
 [2018-10-14 21:34 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened
 [2018-10-14 21:34 UTC] cmb@php.net
Well, we usually don't document bugfixes in the PHP manual. I'm
not sure, though, whether this has been a bugfix, or a change, so
I'm re-opening.
 [2018-10-14 21:40 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC