Skip to content

Commit 6878c58

Browse files
committed
Report error if stream_read is not implemented
We need to return -1 in this case. Slightly restructure the code to avoid unnecessary conditions.
1 parent 382f9b2 commit 6878c58

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Zend/zend_language_scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
523523
return FAILURE;
524524
}
525525

526+
ZEND_ASSERT(!EG(exception) && "stream_fixup() should have failed");
526527
zend_llist_add_element(&CG(open_files), file_handle);
527528
if (file_handle->handle.stream.handle >= (void*)file_handle && file_handle->handle.stream.handle <= (void*)(file_handle+1)) {
528529
zend_file_handle *fh = (zend_file_handle*)zend_llist_get_last(&CG(open_files));

main/streams/userspace.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -671,27 +671,28 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
671671
return -1;
672672
}
673673

674-
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
675-
if (Z_TYPE(retval) == IS_FALSE) {
676-
return -1;
677-
}
678-
679-
if (!try_convert_to_string(&retval)) {
680-
return -1;
681-
}
682-
683-
didread = Z_STRLEN(retval);
684-
if (didread > count) {
685-
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
686-
us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
687-
didread = count;
688-
}
689-
if (didread > 0)
690-
memcpy(buf, Z_STRVAL(retval), didread);
691-
} else if (call_result == FAILURE) {
674+
if (call_result == FAILURE) {
692675
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!",
693676
us->wrapper->classname);
677+
return -1;
678+
}
679+
680+
if (Z_TYPE(retval) == IS_FALSE) {
681+
return -1;
682+
}
683+
684+
if (!try_convert_to_string(&retval)) {
685+
return -1;
686+
}
687+
688+
didread = Z_STRLEN(retval);
689+
if (didread > count) {
690+
php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost",
691+
us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_long)count);
692+
didread = count;
694693
}
694+
if (didread > 0)
695+
memcpy(buf, Z_STRVAL(retval), didread);
695696

696697
zval_ptr_dtor(&retval);
697698
ZVAL_UNDEF(&retval);

0 commit comments

Comments
 (0)