From 98f7efcccf23a3332c2defe5d974f698db58ff9c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 10 Aug 2021 15:37:39 +0200 Subject: [PATCH] Fix #81346: Non-seekable streams don't update position after write The stream position is not related to the buffer, and needs to be updated for non-seekable streams as well. The erroneous condition around the position update is a relict of an old commit[1]. The unexpected test expectation is due to bug #81345. [1] --- ext/standard/tests/streams/bug81346.phpt | 21 +++++++++++++++++++++ main/streams/streams.c | 7 +------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 ext/standard/tests/streams/bug81346.phpt diff --git a/ext/standard/tests/streams/bug81346.phpt b/ext/standard/tests/streams/bug81346.phpt new file mode 100644 index 0000000000000..d70ca9193b663 --- /dev/null +++ b/ext/standard/tests/streams/bug81346.phpt @@ -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-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +int(1100) diff --git a/main/streams/streams.c b/main/streams/streams.c index c1ecf346234b9..d2ee3371c9eb6 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -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;