Skip to content

Commit 77392ee

Browse files
committed
stream: improve filter seeking warning and address some nits
1 parent eb8647f commit 77392ee

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

ext/bz2/tests/bz2_filter_seek_compress.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ Seek to start: SUCCESS
5050
Size after second write: 98
5151
Second write is larger: YES
5252

53-
Warning: fseek(): Stream filter bzip2.compress is not seekable in %s on line %d
53+
Warning: fseek(): Stream filter bzip2.compress is seekable only to start position in %s on line %d
5454
Seek to middle: FAILURE
5555
Decompressed content matches text2: YES

ext/bz2/tests/bz2_filter_seek_decompress.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ First read (20 bytes): I am the very model
3939
Seek to start: SUCCESS
4040
Content after seek matches: YES
4141

42-
Warning: fseek(): Stream filter bzip2.decompress is not seekable in %s on line %d
42+
Warning: fseek(): Stream filter bzip2.decompress is seekable only to start position in %s on line %d
4343
Seek to middle: FAILURE

ext/iconv/tests/iconv_stream_filter_seek.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ First read (20 bytes): Hello, this is a tes
3939
Seek to start: SUCCESS
4040
Content after seek matches: YES
4141

42-
Warning: fseek(): Stream filter convert.iconv.* is not seekable in %s on line %d
42+
Warning: fseek(): Stream filter convert.iconv.* is seekable only to start position in %s on line %d
4343
Seek to middle: FAILURE

ext/standard/tests/filters/convert_filter_seek.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ First read (20 bytes): Hello World! This is
6363
Seek to start: SUCCESS
6464
Content matches: YES
6565

66-
Warning: fseek(): Stream filter convert.* is not seekable in %s on line %d
66+
Warning: fseek(): Stream filter convert.* is seekable only to start position in %s on line %d
6767
Seek to middle: FAILURE
6868

6969
Testing convert.quoted-printable-encode/decode
7070
First read (10 bytes): 4c696e65310d0a4c696e
7171
Seek to start: SUCCESS
7272
Content matches: YES
7373

74-
Warning: fseek(): Stream filter convert.* is not seekable in %s on line %d
74+
Warning: fseek(): Stream filter convert.* is seekable only to start position in %s on line %d
7575
Seek to middle: FAILURE

ext/standard/tests/filters/php_user_filter_04.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ class InvalidSeekFilter extends php_user_filter
2525

2626
?>
2727
--EXPECTF--
28-
Fatal error: Declaration of InvalidSeekFilter::seek($offset): bool must be compatible with php_user_filter::seek(int $offset, int $whence): bool in %s on line %d
28+
Fatal error: Declaration of InvalidSeekFilter::seek($offset): bool must be compatible with php_user_filter::seek(int $offset, int $whence): bool in %s on line %d

ext/standard/user_filters.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ static void userfilter_dtor(php_stream_filter *thisfilter)
133133
zval_ptr_dtor(obj);
134134
}
135135

136-
static zend_result userfilter_assign_stream(php_stream *stream, zval *obj, zend_string **stream_name_p)
136+
static zend_result userfilter_assign_stream(php_stream *stream, zval *obj,
137+
zend_string **stream_name_p, uint32_t orig_no_fclose)
137138
{
138139
/* Give the userfilter class a hook back to the stream */
139140
const zend_class_entry *old_scope = EG(fake_scope);
140141
EG(fake_scope) = Z_OBJCE_P(obj);
141142

142-
zend_string *stream_name = ZSTR_INIT_LITERAL("stream", 0);
143+
zend_string *stream_name = ZSTR_INIT_LITERAL("stream", false);
143144
bool stream_property_exists = Z_OBJ_HT_P(obj)->has_property(Z_OBJ_P(obj), stream_name, ZEND_PROPERTY_EXISTS, NULL);
144145
if (stream_property_exists) {
145146
zval stream_zval;
@@ -149,6 +150,8 @@ static zend_result userfilter_assign_stream(php_stream *stream, zval *obj, zend_
149150
if (EG(exception)) {
150151
EG(fake_scope) = old_scope;
151152
zend_string_release(stream_name);
153+
stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
154+
stream->flags |= orig_no_fclose;
152155
return FAILURE;
153156
}
154157
*stream_name_p = stream_name;
@@ -186,12 +189,10 @@ static php_stream_filter_status_t userfilter_filter(
186189
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
187190

188191
zend_string *stream_name = NULL;
189-
if (userfilter_assign_stream(stream, obj, &stream_name) == FAILURE) {
192+
if (userfilter_assign_stream(stream, obj, &stream_name, orig_no_fclose) == FAILURE) {
190193
if (buckets_in->head) {
191194
php_error_docref(NULL, E_WARNING, "Unprocessed filter buckets remaining on input brigade");
192195
}
193-
stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
194-
stream->flags |= orig_no_fclose;
195196
return PSFS_ERR_FATAL;
196197
}
197198

@@ -283,9 +284,7 @@ static zend_result userfilter_seek(
283284
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
284285

285286
zend_string *stream_name = NULL;
286-
if (userfilter_assign_stream(stream, obj, &stream_name) == FAILURE) {
287-
stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
288-
stream->flags |= orig_no_fclose;
287+
if (userfilter_assign_stream(stream, obj, &stream_name, orig_no_fclose) == FAILURE) {
289288
return FAILURE;
290289
}
291290

ext/zlib/tests/zlib_filter_seek_deflate.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ Seek to start: SUCCESS
5050
Size after second write: %d
5151
Second write is larger: YES
5252

53-
Warning: fseek(): Stream filter zlib.deflate is not seekable in %s on line %d
53+
Warning: fseek(): Stream filter zlib.deflate is seekable only to start position in %s on line %d
5454
Seek to middle: FAILURE
5555
Decompressed content matches text2: YES

ext/zlib/tests/zlib_filter_seek_inflate.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ Seek to start: SUCCESS
4141
Position after seek: 0
4242
Content after seek matches: YES
4343

44-
Warning: fseek(): Stream filter zlib.inflate is not seekable in %s on line %d
44+
Warning: fseek(): Stream filter zlib.inflate is seekable only to start position in %s on line %d
4545
Seek to middle: FAILURE

main/streams/streams.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,12 @@ PHPAPI zend_off_t _php_stream_tell(const php_stream *stream)
13651365
static bool php_stream_are_filters_seekable(php_stream_filter *filter, bool is_start_seeking)
13661366
{
13671367
while (filter) {
1368-
if (filter->seekable == PSFS_SEEKABLE_NEVER ||
1369-
(!is_start_seeking && filter->seekable == PSFS_SEEKABLE_START)) {
1370-
php_error_docref(NULL, E_WARNING, "Stream filter %s is not seekable", filter->fops->label);
1368+
if (filter->seekable == PSFS_SEEKABLE_NEVER) {
1369+
php_error_docref(NULL, E_WARNING, "Stream filter %s is never seekable", filter->fops->label);
1370+
return false;
1371+
}
1372+
if (!is_start_seeking && filter->seekable == PSFS_SEEKABLE_START) {
1373+
php_error_docref(NULL, E_WARNING, "Stream filter %s is seekable only to start position", filter->fops->label);
13711374
return false;
13721375
}
13731376
filter = filter->next;
@@ -1381,7 +1384,7 @@ static zend_result php_stream_filters_seek(php_stream *stream, php_stream_filter
13811384
while (filter) {
13821385
if (((filter->seekable == PSFS_SEEKABLE_START && is_start_seeking) ||
13831386
filter->seekable == PSFS_SEEKABLE_CHECK) &&
1384-
filter->fops->seek(stream, filter, offset, whence)) {
1387+
filter->fops->seek(stream, filter, offset, whence) == FAILURE) {
13851388
php_error_docref(NULL, E_WARNING, "Stream filter seeking for %s failed", filter->fops->label);
13861389
return FAILURE;
13871390
}

0 commit comments

Comments
 (0)