php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51658 Segfault when using stream_filter_append()
Submitted: 2010-04-25 10:23 UTC Modified: 2013-02-18 00:34 UTC
From: slusarz at curecanti dot org Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-04-25 10:23 UTC] slusarz at curecanti dot org
Description:
------------
PHP segfaulting when appending a user-defined filter in WRITE mode.  I can confirm that if I switch to READ mode, or I use a PHP built-in filter, the segfault goes away.

Test script:
---------------
The code that causes this to happen looks like this:

$fp = fopen('php://temp', 'w+');
stream_filter_register('user_filter', 'User_Filter_Class_Name');
stream_filter_append($fp, 'user_filter', STREAM_FILTER_WRITE);


Actual result:
--------------
Program received signal SIGSEGV, Segmentation fault.
0x0000000000743918 in zend_hash_find (ht=0x2682b28, arKey=0xc32354 "stream", 
    nKeyLength=7, pData=0x7fffc9b123f8)
    at /disk2/src/php-5.3.2/Zend/zend_hash.c:880
880		p = ht->arBuckets[nIndex];

-----

#0  0x0000000000743918 in zend_hash_find (ht=0x2682b28, 
    arKey=0xc32354 "stream", nKeyLength=7, pData=0x7fffc9b123f8)
    at /disk2/src/php-5.3.2/Zend/zend_hash.c:880
#1  0x00000000006c2a79 in userfilter_filter (stream=0x269c908, 
    thisfilter=<value optimized out>, buckets_in=0x7fffc9b12480, 
    buckets_out=0x7fffc9b12470, bytes_consumed=0x7fffc9b12498, flags=2)
    at /disk2/src/php-5.3.2/ext/standard/user_filters.c:183
#2  0x00000000006fc727 in _php_stream_write_filtered (stream=0x269c908, 
    buf=<value optimized out>, count=<value optimized out>, flags=2)
    at /disk2/src/php-5.3.2/main/streams/streams.c:997
#3  0x00000000006fc93c in _php_stream_flush (stream=0x269c908, 
    closing=<value optimized out>)
    at /disk2/src/php-5.3.2/main/streams/streams.c:1046
#4  0x00000000006fcb43 in _php_stream_free (stream=0x269c908, close_options=11)
    at /disk2/src/php-5.3.2/main/streams/streams.c:331
#5  0x00000000006fce11 in stream_resource_regular_dtor (
    rsrc=<value optimized out>)
    at /disk2/src/php-5.3.2/main/streams/streams.c:1426
#6  0x0000000000745bbe in list_entry_destructor (ptr=0x269d1c0)
    at /disk2/src/php-5.3.2/Zend/zend_list.c:184
#7  0x0000000000744da5 in zend_hash_del_key_or_index (ht=0xfbdef0, 
    arKey=0xc32354 "stream", nKeyLength=3383829656, h=229483039115121, 
    flag=<value optimized out>) at /disk2/src/php-5.3.2/Zend/zend_hash.c:497
#8  0x0000000000745e67 in _zend_list_delete (id=<value optimized out>)
    at /disk2/src/php-5.3.2/Zend/zend_list.c:58
#9  0x000000000072b8d5 in _zval_dtor (zval_ptr=0x27e6ee8)
    at /disk2/src/php-5.3.2/Zend/zend_variables.h:35
#10 _zval_ptr_dtor (zval_ptr=0x27e6ee8)
    at /disk2/src/php-5.3.2/Zend/zend_execute_API.c:439
#11 0x0000000000742abb in zend_hash_destroy (ht=0x27ab938)
    at /disk2/src/php-5.3.2/Zend/zend_hash.c:526
#12 0x00000000007369d6 in _zval_dtor_func (zvalue=0x269c090)
    at /disk2/src/php-5.3.2/Zend/zend_variables.c:43
#13 0x000000000072b8d5 in _zval_dtor (zval_ptr=0x27add00)
    at /disk2/src/php-5.3.2/Zend/zend_variables.h:35
#14 _zval_ptr_dtor (zval_ptr=0x27add00)
    at /disk2/src/php-5.3.2/Zend/zend_execute_API.c:439
#15 0x0000000000742abb in zend_hash_destroy (ht=0x26469f8)
    at /disk2/src/php-5.3.2/Zend/zend_hash.c:526
#16 0x00000000007369d6 in _zval_dtor_func (zvalue=0x26bfff8)
    at /disk2/src/php-5.3.2/Zend/zend_variables.c:43
#17 0x000000000072b8d5 in _zval_dtor (zval_ptr=0x27e68c0)
    at /disk2/src/php-5.3.2/Zend/zend_variables.h:35
#18 _zval_ptr_dtor (zval_ptr=0x27e68c0)
    at /disk2/src/php-5.3.2/Zend/zend_execute_API.c:439
#19 0x0000000000742abb in zend_hash_destroy (ht=0x26ed608)
    at /disk2/src/php-5.3.2/Zend/zend_hash.c:526
#20 0x0000000000754cd9 in zend_object_std_dtor (object=0x27de0d0)
    at /disk2/src/php-5.3.2/Zend/zend_objects.c:45
#21 0x0000000000754cf9 in zend_objects_free_object_storage (object=0x2682b28)
    at /disk2/src/php-5.3.2/Zend/zend_objects.c:114
#22 0x000000000075816a in zend_objects_store_free_object_storage (
    objects=0xfbe018) at /disk2/src/php-5.3.2/Zend/zend_objects_API.c:92
#23 0x000000000072bc5c in shutdown_executor ()
    at /disk2/src/php-5.3.2/Zend/zend_execute_API.c:302
#24 0x00000000007375e3 in zend_deactivate ()
    at /disk2/src/php-5.3.2/Zend/zend.c:890
#25 0x00000000006e74e0 in php_request_shutdown (dummy=<value optimized out>)
    at /disk2/src/php-5.3.2/main/main.c:1633
#26 0x00000000007bc7a7 in main (argc=<value optimized out>, 
    argv=<value optimized out>)
    at /disk2/src/php-5.3.2/sapi/cgi/cgi_main.c:2152



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-25 12:08 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-04-25 12:08 UTC] pajoye@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2010-04-26 21:57 UTC] slusarz at curecanti dot org
-Status: Feedback +Status: Open
 [2010-04-26 21:57 UTC] slusarz at curecanti dot org
I can't provide a simple test case - it appears that it takes something more than just appending a write filter to a stream (the error is occurring after tens of thousands lines of code were run).

But I did manage to determine that this only happens if the script exits soon after the filter_append with an explicit 'exit' call.  e.g.:

-----

[...code...]

$fp = fopen('php://temp', 'w+');
stream_filter_register('user_filter', 'User_Filter_Class_Name');
stream_filter_append($fp, 'user_filter', STREAM_FILTER_WRITE);

print "TEST";

exit;

[...code...]

-----

will segfault and will not output "TEST" to the browser.  If 'exit;' is removed, no segfault occurs.
 [2010-04-30 00:09 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2010-04-30 00:09 UTC] felipe@php.net
I cannot reproduce this. We need a proper test case.
 [2010-04-30 20:59 UTC] slusarz at curecanti dot org
-Status: Feedback +Status: Closed
 [2010-04-30 20:59 UTC] slusarz at curecanti dot org
I don't have the time to try to track this down further.  The bug still exists, but it obviously requires something more (in terms of program state) than a simple test script can recreate.
 [2010-04-30 21:39 UTC] felipe@php.net
-Status: Closed +Status: Re-Opened
 [2010-05-12 11:47 UTC] mike@php.net
-Status: Re-Opened +Status: Feedback
 [2010-05-12 11:47 UTC] mike@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 20:01:23 2020 UTC