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

From: Date: Mon, 17 Aug 2020 15:12:05 +0000
Subject: Bug #79984 [Com]: Stream filter is not called with closing arg on php://temp streams
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228625@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79984&edit=1

 ID:                 79984
 Comment by:         gehrig at teqneers dot de
 Reported by:        gehrig at teqneers dot de
 Summary:            Stream filter is not called with closing arg on
                     php://temp streams
 Status:             Feedback
 Type:               Bug
 Package:            Streams related
 Operating System:   Official Docker Image
 PHP Version:        7.4.9
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

@cmb@php.net:

Absolutely not. That'd be the output I'd actually expect to start with. I just didn't
bother with the fact that the filter is called a last time with 0 bytes to be consumed and $closing
= true.


Previous Comments:
------------------------------------------------------------------------
[2020-08-17 15:07:17] cmb@php.net

Yes, indeed this is a duplicate of bug #77069.

I have just filed PR #6001[1] which would fix the given tests
script in a slightly different way; instead of

    filtered 128 bytes.
    filtered 0 bytes and closing.

it would output

    filtered 128 bytes and closing.

Would that be an issue?

[1] <https://github.com/php/php-src/pull/6001>

------------------------------------------------------------------------
[2020-08-17 08:28:20] gehrig at teqneers dot de

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 this bug report at https://bugs.php.net/bug.php?id=79984&edit=1


Thread (4 messages)

« previous php.bugs (#228625) next »