Bug #55273 [NEW]: base64_decode with strict rejects whitespace after pad

From: Date: Sat, 23 Jul 2011 21:22:23 +0000
Subject: Bug #55273 [NEW]: base64_decode with strict rejects whitespace after pad
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-162139@lists.php.net to get a copy of this message
From: Operating system: N/A PHP version: 5.3.6 Package: URL related Bug Type: Bug Bug description:base64_decode with strict rejects whitespace after pad 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 bug report at https://bugs.php.net/bug.php?id=55273&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55273&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55273&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55273&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55273&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55273&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55273&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55273&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55273&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55273&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55273&r=support Expected behavior: https://bugs.php.net/fix.php?id=55273&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55273&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55273&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55273&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55273&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55273&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55273&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55273&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55273&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55273&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55273&r=mysqlcfg

« previous php.bugs (#162139) next »