Skip to content

Commit 5664035

Browse files
committed
Also report errors from Zend stream reader operation
1 parent d59aac5 commit 5664035

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Zend/zend_stream.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
ZEND_DLIMPORT int isatty(int fd);
2727

28-
static size_t zend_stream_stdio_reader(void *handle, char *buf, size_t len) /* {{{ */
28+
static ssize_t zend_stream_stdio_reader(void *handle, char *buf, size_t len) /* {{{ */
2929
{
3030
return fread(buf, 1, len, (FILE*)handle);
3131
} /* }}} */
@@ -95,7 +95,7 @@ static int zend_stream_getc(zend_file_handle *file_handle) /* {{{ */
9595
return EOF;
9696
} /* }}} */
9797

98-
static size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len) /* {{{ */
98+
static ssize_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len) /* {{{ */
9999
{
100100
if (file_handle->handle.stream.isatty) {
101101
int c = '*';
@@ -148,10 +148,18 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
148148
}
149149

150150
if (size) {
151-
file_handle->buf = *buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
152-
file_handle->len = zend_stream_read(file_handle, *buf, size);
151+
ssize_t read;
152+
*buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
153+
read = zend_stream_read(file_handle, *buf, size);
154+
if (read < 0) {
155+
efree(*buf);
156+
return FAILURE;
157+
}
158+
file_handle->buf = *buf;
159+
file_handle->len = read;
153160
} else {
154-
size_t read, remain = 4*1024;
161+
size_t remain = 4*1024;
162+
ssize_t read;
155163
*buf = emalloc(remain);
156164
size = 0;
157165

@@ -164,6 +172,11 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
164172
remain = size;
165173
}
166174
}
175+
if (read < 0) {
176+
efree(*buf);
177+
return FAILURE;
178+
}
179+
167180
file_handle->len = size;
168181
if (size && remain < ZEND_MMAP_AHEAD) {
169182
*buf = safe_erealloc(*buf, size, 1, ZEND_MMAP_AHEAD);

Zend/zend_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* These functions are private to the engine.
3030
* */
3131
typedef size_t (*zend_stream_fsizer_t)(void* handle);
32-
typedef size_t (*zend_stream_reader_t)(void* handle, char *buf, size_t len);
32+
typedef ssize_t (*zend_stream_reader_t)(void* handle, char *buf, size_t len);
3333
typedef void (*zend_stream_closer_t)(void* handle);
3434

3535
#define ZEND_MMAP_AHEAD 32

ext/phar/phar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,7 @@ static const zend_function_entry phar_functions[] = {
32153215
};
32163216
/* }}}*/
32173217

3218-
static size_t phar_zend_stream_reader(void *handle, char *buf, size_t len) /* {{{ */
3218+
static ssize_t phar_zend_stream_reader(void *handle, char *buf, size_t len) /* {{{ */
32193219
{
32203220
return php_stream_read(phar_get_pharfp((phar_archive_data*)handle), buf, len);
32213221
}

0 commit comments

Comments
 (0)