Skip to content

Commit ab6ff04

Browse files
committed
Report errors from stream write operations
Fixes bug #73535 and related.
1 parent be7f405 commit ab6ff04

33 files changed

+158
-147
lines changed

ext/bz2/bz2.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,21 @@ static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count)
160160
return ret;
161161
}
162162

163-
static size_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count)
163+
static ssize_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count)
164164
{
165-
size_t wrote = 0;
165+
ssize_t wrote = 0;
166166
struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract;
167167

168-
169168
do {
170169
int just_wrote;
171170
size_t remain = count - wrote;
172171
int to_write = (int)(remain <= INT_MAX ? remain : INT_MAX);
173172

174173
just_wrote = BZ2_bzwrite(self->bz_file, (char*)buf, to_write);
175-
176-
if (just_wrote < 1) {
174+
if (just_wrote < 0) {
175+
return just_wrote;
176+
}
177+
if (just_wrote == 0) {
177178
break;
178179
}
179180

ext/openssl/xp_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
20852085
}
20862086
/* }}} */
20872087

2088-
static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
2088+
static ssize_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
20892089
{
20902090
return php_openssl_sockop_io( 0, stream, (char*)buf, count );
20912091
}

ext/pdo_oci/oci_statement.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ struct oci_lob_self {
634634
ub4 offset;
635635
};
636636

637-
static size_t oci_blob_write(php_stream *stream, const char *buf, size_t count)
637+
static ssize_t oci_blob_write(php_stream *stream, const char *buf, size_t count)
638638
{
639639
struct oci_lob_self *self = (struct oci_lob_self*)stream->abstract;
640640
ub4 amt;
@@ -647,7 +647,7 @@ static size_t oci_blob_write(php_stream *stream, const char *buf, size_t count)
647647
NULL, NULL, 0, SQLCS_IMPLICIT);
648648

649649
if (r != OCI_SUCCESS) {
650-
return (size_t)-1;
650+
return (ssize_t)-1;
651651
}
652652

653653
self->offset += amt;

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in
124124
/* }}} */
125125

126126
/* {{{ pdo_pgsql_create_lob_stream */
127-
static size_t pgsql_lob_write(php_stream *stream, const char *buf, size_t count)
127+
static ssize_t pgsql_lob_write(php_stream *stream, const char *buf, size_t count)
128128
{
129129
struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stream->abstract;
130130
return lo_write(self->conn, self->lfd, (char*)buf, count);

ext/pgsql/pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,9 +5372,9 @@ PHP_FUNCTION(pg_get_pid)
53725372
}
53735373
/* }}} */
53745374

5375-
static size_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
5375+
static ssize_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
53765376
{
5377-
return 0;
5377+
return -1;
53785378
}
53795379
/* }}} */
53805380

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
225225
static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
226226
static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
227227

228-
static size_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count);
228+
static ssize_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count);
229229
static size_t php_pgsql_fd_read(php_stream *stream, char *buf, size_t count);
230230
static int php_pgsql_fd_close(php_stream *stream, int close_handle);
231231
static int php_pgsql_fd_flush(php_stream *stream);

ext/phar/dirstream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ static size_t phar_dir_read(php_stream *stream, char *buf, size_t count) /* {{{
118118
/**
119119
* Dummy: Used for writing to a phar directory (i.e. not used)
120120
*/
121-
static size_t phar_dir_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
121+
static ssize_t phar_dir_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
122122
{
123-
return 0;
123+
return -1;
124124
}
125125
/* }}} */
126126

ext/phar/dirstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
2525
php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options);
2626

2727
/* directory handlers */
28-
static size_t phar_dir_write(php_stream *stream, const char *buf, size_t count);
28+
static ssize_t phar_dir_write(php_stream *stream, const char *buf, size_t count);
2929
static size_t phar_dir_read( php_stream *stream, char *buf, size_t count);
3030
static int phar_dir_close(php_stream *stream, int close_handle);
3131
static int phar_dir_flush(php_stream *stream);

ext/phar/stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,14 @@ static int phar_stream_seek(php_stream *stream, zend_off_t offset, int whence, z
436436
/**
437437
* Used for writing to a phar file
438438
*/
439-
static size_t phar_stream_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
439+
static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
440440
{
441441
phar_entry_data *data = (phar_entry_data *) stream->abstract;
442442

443443
php_stream_seek(data->fp, data->position, SEEK_SET);
444444
if (count != php_stream_write(data->fp, buf, count)) {
445445
php_stream_wrapper_log_error(stream->wrapper, stream->flags, "phar error: Could not write %d characters to \"%s\" in phar \"%s\"", (int) count, data->internal_file->filename, data->phar->fname);
446-
return 0;
446+
return -1;
447447
}
448448
data->position = php_stream_tell(data->fp);
449449
if (data->position > (zend_off_t)data->internal_file->uncompressed_filesize) {

ext/phar/stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
2828
static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context);
2929

3030
/* file/stream handlers */
31-
static size_t phar_stream_write(php_stream *stream, const char *buf, size_t count);
31+
static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t count);
3232
static size_t phar_stream_read( php_stream *stream, char *buf, size_t count);
3333
static int phar_stream_close(php_stream *stream, int close_handle);
3434
static int phar_stream_flush(php_stream *stream);

0 commit comments

Comments
 (0)