From 664c9bc69b393573f5d4616835ef2bb0b7f410f2 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 13 Nov 2024 19:54:43 +0000 Subject: [PATCH] Fix GH-16780: gzseek aborts on non seekable stream. the stream flags is set to non seekable, thus we bail out early in the process. --- main/streams/streams.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/streams/streams.c b/main/streams/streams.c index 4c66d8aadc39b..f306d463b748e 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1321,6 +1321,11 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence) } } + /* the stream is not properly seekable */ + if ((stream->flags & PHP_STREAM_FLAG_NO_SEEK) || (!stream->readpos && stream->position == -1)) { + goto fail; + } + /* handle the case where we are in the buffer */ if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) { switch(whence) { @@ -1393,6 +1398,7 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence) return 0; } +fail: php_error_docref(NULL, E_WARNING, "Stream does not support seeking"); return -1;