Bug #80457 [NEW]: stream_get_contents() fails with maxlength=-1 or default
| From: | bruno dot premont at restena dot lu | Date: | Tue, 01 Dec 2020 15:28:30 +0000 |
| Subject: | Bug #80457 [NEW]: stream_get_contents() fails with maxlength=-1 or default | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-230770@lists.php.net to get a copy of this message | ||
From: bruno dot premont at restena dot lu
Operating system: Linux, x32
PHP version: 7.3.25
Package: Filesystem function related
Bug Type: Bug
Bug description:stream_get_contents() fails with maxlength=-1 or default
Description:
------------
The change introduced in commit 62dce97973436f1830b18304e7939a03b18d44ba
(Require non-negative length in stream_get_contents()) causes
stream_get_contents() to fail if no maxlength is provided and even if
maxlength is explicitly provided as -1.
This also causes some stream tests to fail.
The cause of the failure is the mix of type conversions where parts are
signed and parts are unsigned.
Under X32 zend_long is 64bit but size_t and ssize_t seem not to be.
Thus
zend_long maxlength = (ssize_t)PHP_STREAM_COPY_ALL;
will store -1
but
maxlength == PHP_STREAM_COPY_ALL
will compare a signed and a unsigned value causing trouble due to
extending unsigned 32bit PHP_STREAM_COPY_ALL to a signed 64bit value.
Blindly converting between unsigned PHP_STREAM_COPY_ALL and signed
zend_long is prone to trouble.
Other probably affected code:
phar extension (passing zend_long to php_stream_copy_to_mem() which
takes a size_t for maxlength after eventually having assigned
PHP_STREAM_COPY_ALL to the zend_long.
--
Edit bug report at https://bugs.php.net/bug.php?id=80457&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80457&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80457&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80457&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80457&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80457&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80457&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80457&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80457&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80457&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80457&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80457&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80457&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80457&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80457&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80457&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80457&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80457&r=mysqlcfg