Fix #81477: LimitIterator + SplFileObject regression in 8.0.1

We must not free the read line, if the `READ_AHEAD` flag is set.  This
also restores the expectations of SplFileObject_next_variation002.phpt.

Closes GH-7518.
This commit is contained in:
Christoph M. Becker 2021-09-27 13:07:04 +02:00
parent e2d9ca7b19
commit ee5711de33
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
4 changed files with 33 additions and 2 deletions

1
NEWS
View File

@ -32,6 +32,7 @@ PHP NEWS
- SPL:
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
(cmb, Nikita, Tyson Andre)
. Fixed bug #81477 (LimitIterator + SplFileObject regression in 8.0.1). (cmb)
- Standard:
. Fixed bug #69751 (Change Error message of sprintf/printf for missing/typo

View File

@ -2738,7 +2738,9 @@ PHP_METHOD(SplFileObject, seek)
}
if (line_pos > 0) {
intern->u.file.current_line_num++;
spl_filesystem_file_free_line(intern);
if (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
spl_filesystem_file_free_line(intern);
}
}
} /* }}} */

View File

@ -26,5 +26,5 @@ echo $s->current();
--EXPECT--
//line 3
//line 4
//line 3
//line 4
//line 5

View File

@ -0,0 +1,28 @@
--TEST--
Bug #81477 (LimitIterator + SplFileObject regression in 8.0.1)
--FILE--
<?php
$filename = __DIR__ . '/bug81477.csv';
$s = fopen($filename, 'w+');
fwrite($s, "foo,bar\nbaz,bat\nmore,data\n");
fclose($s);
$sfo = new SplFileObject($filename);
$sfo->setFlags(SplFileObject::READ_AHEAD);
$limitIter = new LimitIterator($sfo, 1, -1);
foreach($limitIter as $row) {
var_dump($row);
}
?>
--EXPECT--
string(8) "baz,bat
"
string(10) "more,data
"
string(0) ""
--CLEAN--
<?php
@unlink(__DIR__ . '/bug81477.csv');
?>