Skip to content

Commit ee5711d

Browse files
committed
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.
1 parent e2d9ca7 commit ee5711d

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PHP NEWS
3232
- SPL:
3333
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
3434
(cmb, Nikita, Tyson Andre)
35+
. Fixed bug #81477 (LimitIterator + SplFileObject regression in 8.0.1). (cmb)
3536

3637
- Standard:
3738
. Fixed bug #69751 (Change Error message of sprintf/printf for missing/typo

ext/spl/spl_directory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,9 @@ PHP_METHOD(SplFileObject, seek)
27382738
}
27392739
if (line_pos > 0) {
27402740
intern->u.file.current_line_num++;
2741-
spl_filesystem_file_free_line(intern);
2741+
if (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
2742+
spl_filesystem_file_free_line(intern);
2743+
}
27422744
}
27432745
} /* }}} */
27442746

ext/spl/tests/SplFileObject_next_variation002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ echo $s->current();
2626
--EXPECT--
2727
//line 3
2828
//line 4
29+
//line 3
2930
//line 4
30-
//line 5

ext/spl/tests/bug81477.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #81477 (LimitIterator + SplFileObject regression in 8.0.1)
3+
--FILE--
4+
<?php
5+
$filename = __DIR__ . '/bug81477.csv';
6+
7+
$s = fopen($filename, 'w+');
8+
fwrite($s, "foo,bar\nbaz,bat\nmore,data\n");
9+
fclose($s);
10+
11+
$sfo = new SplFileObject($filename);
12+
$sfo->setFlags(SplFileObject::READ_AHEAD);
13+
$limitIter = new LimitIterator($sfo, 1, -1);
14+
15+
foreach($limitIter as $row) {
16+
var_dump($row);
17+
}
18+
?>
19+
--EXPECT--
20+
string(8) "baz,bat
21+
"
22+
string(10) "more,data
23+
"
24+
string(0) ""
25+
--CLEAN--
26+
<?php
27+
@unlink(__DIR__ . '/bug81477.csv');
28+
?>

0 commit comments

Comments
 (0)