Skip to content

Commit c2c5c9a

Browse files
committed
Use reported fstat filesize for PHP streams
1 parent 856c5d2 commit c2c5c9a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

Zend/zend_stream.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,16 @@ static size_t zend_stream_stdio_fsizer(void *handle) /* {{{ */
4848
#endif
4949
return buf.st_size;
5050
}
51-
return 0;
51+
return -1;
5252
} /* }}} */
5353

5454
static size_t zend_stream_fsize(zend_file_handle *file_handle) /* {{{ */
5555
{
56-
zend_stat_t buf;
57-
58-
if (file_handle->type == ZEND_HANDLE_STREAM) {
59-
return file_handle->handle.stream.fsizer(file_handle->handle.stream.handle);
60-
}
61-
if (file_handle->handle.fp && zend_fstat(fileno(file_handle->handle.fp), &buf) == 0) {
62-
#ifdef S_ISREG
63-
if (!S_ISREG(buf.st_mode)) {
64-
return 0;
65-
}
66-
#endif
67-
return buf.st_size;
56+
ZEND_ASSERT(file_handle->type == ZEND_HANDLE_STREAM);
57+
if (file_handle->handle.stream.isatty) {
58+
return 0;
6859
}
69-
70-
return -1;
60+
return file_handle->handle.stream.fsizer(file_handle->handle.stream.handle);
7161
} /* }}} */
7262

7363
ZEND_API void zend_stream_init_fp(zend_file_handle *handle, FILE *fp, const char *filename) {
@@ -126,7 +116,6 @@ static size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t
126116
ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len) /* {{{ */
127117
{
128118
size_t size;
129-
zend_bool is_fp = 0;
130119

131120
if (file_handle->buf) {
132121
*buf = file_handle->buf;
@@ -145,7 +134,6 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
145134
return FAILURE;
146135
}
147136

148-
is_fp = 1;
149137
file_handle->type = ZEND_HANDLE_STREAM;
150138
file_handle->handle.stream.handle = file_handle->handle.fp;
151139
file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle));
@@ -159,7 +147,7 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t
159147
return FAILURE;
160148
}
161149

162-
if (is_fp && !file_handle->handle.stream.isatty && size) {
150+
if (size) {
163151
file_handle->buf = *buf = safe_emalloc(1, size, ZEND_MMAP_AHEAD);
164152
file_handle->len = zend_stream_read(file_handle, *buf, size);
165153
} else {

0 commit comments

Comments
 (0)