Bug #79984 [NEW]: Stream filter is not called with closing arg on php://temp streams

From: Date: Mon, 17 Aug 2020 08:28:20 +0000
Subject: Bug #79984 [NEW]: Stream filter is not called with closing arg on php://temp streams
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228619@lists.php.net to get a copy of this message
From:             gehrig at teqneers dot de
Operating system: Official Docker Image
PHP version:      7.4.9
Package:          Streams related
Bug Type:         Bug
Bug description:Stream filter is not called with closing arg on php://temp streams

Description:
------------
As seen in script https://3v4l.org/egsEi a simple stream filter
is
created. It outputs some debug information on php_user_filter::onCreate,
php_user_filter::onClose and on each call to php_user_filter::filter.

The stream filter is then attached to streams based on 

a) tmpfile()
b) a php://temp stream
c) a php://memory stream

While a) and c) produce the correct result in all PHP versions, b)
behaves differently on PHP 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 -
7.4.9, 8.0.0alpha1 - beta1 (according to https://3v4l.org). 

As seen from the output the stream filter attached to the php://temp
stream is only called twice (b) while in the other examples it's called
three times (a and c) - with 0 bytes left to consume but $closing = true
on the last call. The "$closing = true" call is missing when using a
php://temp (b). 
Older versions of PHP (5.5.21 - 5.5.38, 5.6.5 - 5.6.40, 7.0.0 - 7.0.33,
7.1.0 - 7.1.33) do not show this kind of behaviour, while even older
ones (5.3.29, 5.4.19 - 5.4.45, 5.5.1 - 5.5.20, 5.6.0 - 5.6.4) show the
same behaviour even on php://memory streams (c). 

I'm not sure but this one may be related to #68948
(https://bugs.php.net/bug.php?id=68948) and it might even be a duplicate
of #77069 (https://bugs.php.net/bug.php?id=77069).

Test script:
---------------
https://3v4l.org/egsEi

Expected result:
----------------
tmpfile()
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
filtered 0 bytes and closing.
A...A // shortened - 8320 bytes
filter onClose


php://temp
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
filtered 0 bytes and closing.
A...A // shortened - 8320 bytes
filter onClose


php://memory
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
filtered 0 bytes and closing.
A...A // shortened - 8320 bytes
filter onClose


Actual result:
--------------
tmpfile()
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
filtered 0 bytes and closing.
A...A // shortened - 8320 bytes
filter onClose


php://temp
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
A...A // shortened - 8320 bytes
filter onClose


php://memory
filter onCreate
filtered 8192 bytes.
filtered 128 bytes.
filtered 0 bytes and closing.
A...A // shortened - 8320 bytes
filter onClose


-- 
Edit bug report at https://bugs.php.net/bug.php?id=79984&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79984&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79984&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79984&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79984&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79984&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79984&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79984&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79984&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79984&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79984&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79984&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79984&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79984&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79984&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79984&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79984&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79984&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#228619) next »