Skip to content

Commit d08b4db

Browse files
committed
Fix Bug #66736 fpassthru broken
1 parent 7ab5c59 commit d08b4db

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
. Fixed bug #64330 (stream_socket_server() creates wrong Abstract Namespace
88
UNIX sockets). (Mike)
99
. Fixed bug #66182 (exit in stream filter produces segfault). (Mike)
10+
. Fixed bug #66736 (fpassthru broken). (Mike)
1011

1112
- Embed:
1213
. Fixed bug #65715 (php5embed.lib isn't provided anymore). (Anatol)

main/output.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ PHPAPI int php_output_get_status(TSRMLS_D)
234234
* Unbuffered write */
235235
PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
236236
{
237+
#if PHP_DEBUG
238+
if (len > UINT_MAX) {
239+
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
240+
"output will be truncated %lu => %lu",
241+
(unsigned long) len, (unsigned long) (len % UINT_MAX));
242+
}
243+
#endif
237244
if (OG(flags) & PHP_OUTPUT_DISABLED) {
238245
return 0;
239246
}
@@ -248,6 +255,13 @@ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
248255
* Buffered write */
249256
PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC)
250257
{
258+
#if PHP_DEBUG
259+
if (len > UINT_MAX) {
260+
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
261+
"output will be truncated %lu => %lu",
262+
(unsigned long) len, (unsigned long) (len % UINT_MAX));
263+
}
264+
#endif
251265
if (OG(flags) & PHP_OUTPUT_DISABLED) {
252266
return 0;
253267
}

main/streams/streams.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,11 +1405,16 @@ PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC)
14051405
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
14061406

14071407
if (p) {
1408-
PHPWRITE(p, mapped);
1408+
do {
1409+
/* output functions return int, so pass in int max */
1410+
if (0 < (b = PHPWRITE(p, MIN(mapped - bcount, INT_MAX)))) {
1411+
bcount += b;
1412+
}
1413+
} while (b > 0 && mapped > bcount);
14091414

14101415
php_stream_mmap_unmap_ex(stream, mapped);
14111416

1412-
return mapped;
1417+
return bcount;
14131418
}
14141419
}
14151420

0 commit comments

Comments
 (0)