Solved bug #24842, memory corruption

php.internals

Vesselin Atanasov

23 years ago
Hello. I found the cause for bug #24842. In function shutdown_executor(), the "arg_types_stack" stack is cleaned way too early, and later when some destructor calls a function like printf(), the helper function zend_do_fcall_handler() uses the "arg_types_stack", which is freed earlier, thus overwriting any data that has replaced the arg_types_stack->elements memory block. A small patch follows: diff -ruN php5-200307300330.orig/Zend/zend_execute_API.c php5-200307300330/Zend/zend_execute_API.c --- php5-200307300330.orig/Zend/zend_execute_API.c 2003-07-27 17:07:14.000000000 +0000 +++ php5-200307300330/Zend/zend_execute_API.c 2003-07-30 07:55:39.000000000 +0000 @@ -189,7 +189,10 @@ void shutdown_executor(TSRMLS_D) { zend_try { +/* Moved after symbol table cleaners because arg_types_stack is used by zend_do_fcall_handler(), so if a + destructor calls a function like printf() it will cause memory corruption zend_ptr_stack_destroy(&EG(arg_types_stack)); + */ /* Removed because this can not be safely done, e.g. in this situation: Object 1 creates object 2 @@ -286,6 +289,7 @@ zend_hash_destroy(&EG(included_files)); + zend_ptr_stack_destroy(&EG(arg_types_stack)); zend_ptr_stack_destroy(&EG(user_error_handlers)); zend_ptr_stack_destroy(&EG(user_exception_handlers)); zend_objects_store_destroy(&EG(objects_store));

John Coggeshall

23 years ago
Hey all: I've written a new extension for PHP (ZE2 only) Based on the famed HTML Tidy's (http://tidy.sf.net/) library. This extension provides more than just an incredibly easy way to clean and repair HTML documents, and includes API for traversing an arbitrary HTML document using the ZE2 OO support. I've put the extension, basic PHPDocs, working examples, tests, and of course the extension itself on my web site: http://www.coggeshall.org/php/php-tidy-0-5b.tar.gz Although I haven't written true PHPDocs yet, README_TIDY in the tidy/ directory outlines the API including a description of the OO methods and proprieties available to accessing the parsed HTML document tree. I am interested in hearing from the internal@ community on my extension and finding out what everyone thinks of it. There are memleaks which still need to be tracked down (which I believe either have to do with ZE2 itself or because I am missing something in my OO implementation), and I know there are probably bugs.. I'd welcome suggestions, patches, and even just "it broke doing this". I plan on maintaining this extension on my web site and perhaps PECL (unless of course this is something worthy for the standard PHP5 distro), so if nothing else you can always find it there. Regards, John PS -- Here is a paste of one of the examples for those who are curious to how the OO stuff works (pulls all <A HREF> links out): <?php /* Create a Tidy Resource */ $tidy = tidy_create(); /* Parse the document */ tidy_parse_file($tidy, $_SERVER['argv'][1]); /* Fix up the document */ tidy_clean_repair($tidy); /* Get an object representing everything from the <HTML> tag in */ $html = tidy_get_html($tidy); /* Traverse the document tree */ print_r(get_links($html)); function get_links($node) { $urls = array(); /* Check to see if we are on an <A> tag or not */ if($node->id == TIDY_TAG_A) { /* If we are, find the HREF attribute */ $attrib = $node->get_attr_type(TIDY_ATTR_HREF); if($attrib) { /* Add the value of the HREF attrib to $urls */ $urls[] = $attrib->value; } } /* Are there any children? */ if($node->has_children()) { /* Traverse down each child recursively */ foreach($node->children as $child) { /* Append the results from recursion to $urls */ foreach(get_links($child) as $url) { $urls[] = $url; } } } return $urls; } ?>
-- -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~- John Coggeshall john at coggeshall dot org http://www.coggeshall.org/ -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~-

(Marcus Börger)

23 years ago
Hello John, Wednesday, July 30, 2003, 1:26:02 PM, you wrote: JC> Hey all: JC> I've written a new extension for PHP (ZE2 only) Based on the famed HTML JC> Tidy's (http://tidy.sf.net/) library. This extension provides more than JC> just an incredibly easy way to clean and repair HTML documents, and JC> includes API for traversing an arbitrary HTML document using the ZE2 OO JC> support. JC> I've put the extension, basic PHPDocs, working examples, tests, and of JC> course the extension itself on my web site: JC> http://www.coggeshall.org/php/php-tidy-0-5b.tar.gz JC> Although I haven't written true PHPDocs yet, README_TIDY in the tidy/ JC> directory outlines the API including a description of the OO methods and JC> proprieties available to accessing the parsed HTML document tree. JC> I am interested in hearing from the internal@ community on my extension JC> and finding out what everyone thinks of it. There are memleaks which JC> still need to be tracked down (which I believe either have to do with JC> ZE2 itself or because I am missing something in my OO implementation), JC> and I know there are probably bugs.. I'd welcome suggestions, patches, JC> and even just "it broke doing this". JC> I plan on maintaining this extension on my web site and perhaps PECL JC> (unless of course this is something worthy for the standard PHP5 JC> distro), so if nothing else you can always find it there. Some months ago i had a similar idea, mainly to have it as an output handler. So in general i think it's a cool idea. So my question is will you provide such an output handler? Besides that i think you should put it into PECL :-)
-- Best regards, Marcus mailto:helly@php.net

Unnamed Person

23 years ago
"Marcus BöRger" <marcus.boerger@t-online.de> a écrit dans le message de news:992327984.20030730202356@post.rwth-aachen.de...
> Hello John, > > Wednesday, July 30, 2003, 1:26:02 PM, you wrote: > > JC> Hey all: > > JC> I've written a new extension for PHP (ZE2 only) Based on the famed
HTML
> JC> Tidy's (http://tidy.sf.net/) library. This extension provides more
than
> JC> just an incredibly easy way to clean and repair HTML documents, and > JC> includes API for traversing an arbitrary HTML document using the ZE2
OO
> JC> support. > > JC> I've put the extension, basic PHPDocs, working examples, tests, and of > JC> course the extension itself on my web site: > > JC> http://www.coggeshall.org/php/php-tidy-0-5b.tar.gz > > JC> Although I haven't written true PHPDocs yet, README_TIDY in the tidy/ > JC> directory outlines the API including a description of the OO methods
and
> JC> proprieties available to accessing the parsed HTML document tree. > > JC> I am interested in hearing from the internal@ community on my
extension
> JC> and finding out what everyone thinks of it. There are memleaks which > JC> still need to be tracked down (which I believe either have to do with > JC> ZE2 itself or because I am missing something in my OO implementation), > JC> and I know there are probably bugs.. I'd welcome suggestions, patches, > JC> and even just "it broke doing this". > > JC> I plan on maintaining this extension on my web site and perhaps PECL > JC> (unless of course this is something worthy for the standard PHP5 > JC> distro), so if nothing else you can always find it there. > > Some months ago i had a similar idea, mainly to have it as an output
handler.
> So in general i think it's a cool idea. So my question is will you provide > such an output handler? > > Besides that i think you should put it into PECL :-)
+1 too.
> > > > -- > Best regards, > Marcus mailto:helly@php.net >
-- Regards. M.CHAILLAN Nicolas nicos@php.net www.WorldAKT.com Hébergement de sites internets.

John Coggeshall

23 years ago
> Some months ago i had a similar idea, mainly to have it as an output handler. > So in general i think it's a cool idea. So my question is will you provide > such an output handler?
I actually was bugging Wez about filters for this exact reason. :)
> Besides that i think you should put it into PECL :-)
just requested an account. John
-- -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~- John Coggeshall john at coggeshall dot org http://www.coggeshall.org/ -~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~--~=~-