diff options
author | Albert Casademont <albertcasademont@gmail.com> | 2019-07-23 14:03:06 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-29 17:33:57 +0200 |
commit | dc7aa22b18b710aaa837c9466e9a77241f909c8a (patch) | |
tree | a5a8b43accc8e24cc13f92b4ac461423e53dc0af /main | |
parent | 38f1288b6427fc9e2fa2b5ad9912745ded923ee7 (diff) | |
download | php-git-dc7aa22b18b710aaa837c9466e9a77241f909c8a.tar.gz |
Fix bug #78326
Similar to what fread() does, truncate the stream_get_contents()
result if the original buffer was way too large.
Diffstat (limited to 'main')
-rw-r--r-- | main/streams/streams.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c index 9daae57433..399ec29810 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1418,8 +1418,13 @@ PHPAPI zend_string *_php_stream_copy_to_mem(php_stream *src, size_t maxlen, int ptr += ret; } if (len) { - *ptr = '\0'; ZSTR_LEN(result) = len; + ZSTR_VAL(result)[len] = '\0'; + + /* Only truncate if the savings are large enough */ + if (len < maxlen / 2) { + result = zend_string_truncate(result, len, persistent); + } } else { zend_string_free(result); result = NULL; |