#44583 [NEW]: base64_decode: innaccurate documentation for $strict argument
| From: | robin_fernandes at uk dot ibm dot com | Date: | Mon, 31 Mar 2008 16:03:37 +0000 |
| Subject: | #44583 [NEW]: base64_decode: innaccurate documentation for $strict argument | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-643@lists.php.net to get a copy of this message | ||
From: robin_fernandes at uk dot ibm dot com
Operating system: Windows
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: base64_decode: innaccurate documentation for $strict argument
Description:
------------
In the doc for base64_decode(), the description of the $strict parameter
reads:
"Returns FALSE if input contains space or some other separator."
In fact, the return value of base64_decode() is not affected by spaces or
other white-space chars, regardless of the $strict flag. It is, however,
affected by other chars outside of the base64 alphabet. See reproduce
code.
The implementation in base64.c suggests this is intentional:
if ((!strict && ch < 0) || ch == -1) { /* a space or some other separator
character, we simply skip over */
continue;
}
A better description for the $strict param would be:
"When true, base64_decode() will return false if the data contains a
non-whitespace character outside of the base64 alphabet. When false, all
characters outside of the base64 alphabet are simply ignored."
FYI, here's what RFC 2045 (referred to in the doc) has to say about how
the decoder should deal with chars outside of the base64 alphabet:
"All line breaks or other characters not found in Table 1 must be ignored
by decoding software. In base64 data, characters other than those in Table
1, line breaks, and other white space probably indicate a transmission
error, about which a warning message or even a message rejection might be
appropriate under some circumstances."
Reproduce code:
---------------
<?php
echo "Whitespace does not affect base64_decode, even with
\$strict===true:\n";
$noWhiteSpace = "aGVsbG8gd29ybGQh";
var_dump(base64_decode($noWhiteSpace, false));
var_dump(base64_decode($noWhiteSpace, true));
$withWhiteSpace = "a GVs bG8gd2
9ybGQh";
var_dump(base64_decode($withWhiteSpace, false));
var_dump(base64_decode($withWhiteSpace, true));
echo "\n\nOther chars outside the base64 alphabet are ignored when
\$strict===false, but cause failure with \$strict===true:\n";
$badChars = $noWhiteSpace . '*';
var_dump(base64_decode($badChars, false));
var_dump(base64_decode($badChars, true));
?>
Expected result:
----------------
n/a
Actual result:
--------------
Whitespace does not affect base64_decode, even with $strict===true:
string(12) "hello world!"
string(12) "hello world!"
string(12) "hello world!"
string(12) "hello world!"
Other chars outside the base64 alphabet are ignored when $strict===false,
but cause failure with $strict===true:
string(12) "hello world!"
bool(false)
--
Edit bug report at http://bugs.php.net/?id=44583&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44583&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44583&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44583&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44583&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44583&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44583&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44583&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44583&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44583&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44583&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44583&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44583&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44583&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44583&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44583&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44583&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44583&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44583&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44583&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44583&r=mysqlcfg