|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-03-15 20:28 UTC] bugs at jth dot net
Description:
------------
When decoding a string containing two or more base64 blocks with line feeds in the base64 text the latter blocks are corrupted.
This may occur as input from an email generated by some mail programs.
Test script:
---------------
$s1 = base64_encode("Line nr 1 bcdefg\n");
$s2 = base64_encode("Line nr 2 \n");
$str = $s1."\n".$s2;
echo $str
echo base64_decode($str);
Expected result:
----------------
TGluZSBuciAxIGJjZGVmZwo=
TGluZSBuciAyIAo=
Line nr 1 bcdefg
Line nr 2
Actual result:
--------------
Result:
TGluZSBuciAxIGJjZGVmZwo=
TGluZSBuciAyIAo=
Line nr 1 bcdefg
(corrupted text)
Patchesbase64_encode_testscript (last revision 2021-04-13 15:03 UTC by bugs at jth dot net)base64_patch (last revision 2021-04-13 14:55 UTC by bugs at jth dot net) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
What if the first block isn't padded with '=' because the data it's encoding is a multiple of three bytes in length? $s1 = base64_encode("Line nr 1 bcdefgh\n"); $s2 = base64_encode("Line nr 2 \n"); $str = $s1."\n".$s2; echo $str; echo base64_decode($str);