Skip to content

Commit 471818b

Browse files
committed
Add regression test for append-mode negative position fix
1 parent a99c06b commit 471818b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-21700: Append-mode open ignores a negative position returned by a user stream
3+
--FILE--
4+
<?php
5+
class lyingstream {
6+
public function stream_open($path, $mode, $options, &$opened_path) { return true; }
7+
public function stream_seek($offset, $whence) { return true; }
8+
public function stream_tell(): int { return -42; }
9+
public function stream_eof() { return false; }
10+
public function stream_read($count) { return ''; }
11+
}
12+
13+
stream_wrapper_register("test", "lyingstream");
14+
15+
// Opening in append mode triggers an internal SEEK_CUR to revise the initial
16+
// position; if the user stream lies, ftell() must still report a non-negative
17+
// value and a subsequent SEEK_CUR must not trip the position invariant.
18+
$fp = fopen("test://foo", "ab");
19+
var_dump(ftell($fp));
20+
var_dump(fseek($fp, 0, SEEK_CUR));
21+
fclose($fp);
22+
23+
stream_wrapper_unregister("test");
24+
?>
25+
--EXPECT--
26+
int(0)
27+
int(-1)

0 commit comments

Comments
 (0)