Bug #55273 [Opn->Csd]: base64_decode with strict rejects whitespace after pad

From: Date: Mon, 12 Sep 2011 17:20:19 +0000
Subject: Bug #55273 [Opn->Csd]: base64_decode with strict rejects whitespace after pad
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-163472@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55273&edit=1 ID: 55273 Updated by: iliaa@php.net Reported by: ljb9832 at pobox dot com Summary: base64_decode with strict rejects whitespace after pad -Status: Open +Status: Closed Type: Bug Package: URL related Operating System: N/A PHP Version: 5.3.6 -Assigned To: +Assigned To: iliaa Block user comment: N Private report: N New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. For Windows: http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2011-09-12 17:20:09] iliaa@php.net Automatic comment from SVN on behalf of iliaa Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=316560 Log: Fixed bug #55273 (base64_decode() with strict rejects whitespace after pad) ------------------------------------------------------------------------ [2011-07-23 21:22:22] ljb9832 at pobox dot com Description: ------------ Per RFC2045, section 6.8, base64 decoding should not count line breaks and other whitespace as errors. When using $strict=True, base64_decode() does ignore whitespace, except at the end of any base64 encoded data that ends with padding characters (=). If there is whitespace after the padding character(s), the string is rejected under strict testing. This is incorrect. One particular problem with this is that you cannot reliably round-trip base64 encode/decode with strict checking when using chunk_split() on the encoded data, because chunk_split puts a newline at the end of the data. If the length of the original data is a multiple of 3, it works, otherwise it does not. Test script: --------------- <?php function test($s) { $v = chunk_split(base64_encode($s)); $r = base64_decode($v, True); echo "$s="; var_dump($r); } test('PHP'); test('PH'); test('P'); Expected result: ---------------- PHP=string(3) "PHP" PH=string(2) "PH" P=string(1) "P" Actual result: -------------- PHP=string(3) "PHP" PH=bool(false) P=bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55273&edit=1

« previous php.bugs (#163472) next »