From: Operating system: ALL PHP version: 5.3.2 Package: *Compression related Bug Type: Bug Bug description:base64_decode() improper handling of leading padding.
Description: ------------ According to the MIME standard that we're following, this isn't supposed to work when strict mode is enabled. Equal-signs are strictly reserved for padding characters at the _end_ of a base64 MIME string. Leading '=' signs are allowed in each block of 4 bytes because the condition that checks for invalid placement of the '=' signs only checks if (i % 4) == 1, Whereas it should check if (i % 4) is 0 or 1. You should be able to change the circumstances for a valid '=' placement, as follows, to conform to the standard: // to see if bit position 2 is set (for all values of i = n*4+2 and i = n*4+3) if (i & 2) // means that the '=' is in a valid location I would also suggest *carefully* looking over the block at the end of the base64_decode() function... as it seems that if (ch == base64_pad) after ch is ALWAYS set to '\0' is an impossible scenario. Test script: --------------- <?php echo base64_decode('=VGhl=ICc9=JyBz=eW1i=b2xz=IGFy=ZW4n=dCBh=bGxv=d2Vk=IHdo=ZXJl=IGkg=cHV0=IHRo=ZW0g=by5P'); ?> Expected result: ---------------- should return FALSE/NULL/Errornous value Actual result: -------------- echos: The '=' symbols aren't allowed where i put them o.O -- Edit bug report at http://bugs.php.net/bug.php?id=52327&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52327&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52327&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52327&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52327&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52327&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52327&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52327&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52327&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52327&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52327&r=support Expected behavior: http://bugs.php.net/fix.php?id=52327&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52327&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52327&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52327&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52327&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52327&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52327&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52327&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52327&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52327&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52327&r=mysqlcfg