Skip to content

Fix #81346: Non-seekable streams don't update position after write #7356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ext/standard/tests/streams/bug81346.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #81346 (Non-seekable streams don't update position after write)
--DESCRIPTION--
The test expectation is due to bug #81345.
--SKIPIF--
<?php
if (!extension_loaded('bz2')) die("bz2 extension not available");
?>
--FILE--
<?php
$s = fopen("compress.bzip2://" . __DIR__ . "/bug81346.bz2", "w");
fwrite($s, str_repeat("hello world", 100));
fflush($s);
var_dump(ftell($s));
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/bug81346.bz2");
?>
--EXPECT--
int(1100)
7 changes: 1 addition & 6 deletions main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,12 +1151,7 @@ static ssize_t _php_stream_write_buffer(php_stream *stream, const char *buf, siz
buf += justwrote;
count -= justwrote;
didwrite += justwrote;

/* Only screw with the buffer if we can seek, otherwise we lose data
* buffered from fifos and sockets */
if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
stream->position += justwrote;
}
stream->position += justwrote;
}

return didwrite;
Expand Down