fgetss() fails due to parameter that can't be set
| Bug #52163 | SplFileObject::fgetss() fails due to parameter that can't be set | ||||
|---|---|---|---|---|---|
| Submitted: | 2010-06-23 21:16 UTC | Modified: | 2010-06-25 01:11 UTC | ||
| From: | v-ryanbi at microsoft dot com | Assigned: | felipe (profile) | ||
| Status: | Closed | Package: | SPL related | ||
| PHP Version: | 5.2.14RC1 | OS: | Windows 7 | ||
| Private report: | No | CVE-ID: | None | ||
[2010-06-23 21:16 UTC] v-ryanbi at microsoft dot com
Description:
------------
When calling SplFileObject::ffgetss() in 5.2.x (including the 5.2.14 RC1), a
warning is thrown and the cursor is *not* advanced. Since this would typically be
used in a while(!$fileObj->eof()) loop, it can result in an infinite loop.
The complaint thrown in the warning is that the Length parameter must be greater
than 0. While Length is a valid parameter in the global fgetss function, the SPL
version of this function only accepts one parameter, and that is for accepted
tags.
Test script:
---------------
<?php
$str = <<<EOD
<html><body>
<p>Welcome! Today is the <?php echo(date('jS')); ?> of <?= date('F'); ?>.</p>
</body></html>
Text outside of the HTML block.
EOD;
$filePath="filename.php";
file_put_contents($filePath, $str);
$fileObject = new SplFileObject($filePath);
while (!$fileObject->eof()) {
echo $fileObject->fgetss('body');
}
?>
Expected result:
----------------
Welcome! Today is the of .
Text outside of the HTML block.
Actual result:
--------------
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
Warning: fgetss(): Length parameter must be greater than 0 in
C:\fgetssBug\fgetss_basic.php on line 13
... and on to infinity.
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2010-06-23 21:18 UTC] v-ryanbi at microsoft dot com
-Summary: fails due to parameter that can't be set +Summary: SplFileObject::fgetss() fails due to parameter that can't be set
[2010-06-23 21:18 UTC] v-ryanbi at microsoft dot com
[2010-06-25 01:11 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
[2010-06-25 01:11 UTC] felipe@php.net