php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64017 php_libxml_initialize overwrites global entity loader
Submitted: 2013-01-18 11:28 UTC Modified: 2013-02-18 00:36 UTC
From: piotrek dot pokora at gmail dot com Assigned:
Status: No Feedback Package: CGI/CLI related
PHP Version: 5.4.11 OS: Linux/Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: piotrek dot pokora at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-18 11:28 UTC] piotrek dot pokora at gmail dot com
Description:
------------
php_libxml_initialize function in ext/libxml sets global entity loader via xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader). This affects any library which is loaded implicitly during loading phase and triggers segmentation fault.

Gdb output:

Program received signal SIGSEGV, Segmentation fault.
_zend_hash_index_update_or_next_insert (ht=0xd1b910, h=0, pData=<value optimized out>, nDataSize=16, pDest=0x0, flag=1)
    at /app/php-5.4.8/Zend/zend_hash.c:385
385	/app/php-5.4.8/Zend/zend_hash.c: No such file or directory.
	in /app/php-5.4.8/Zend/zend_hash.c
(gdb) bt
#0  _zend_hash_index_update_or_next_insert (ht=0xd1b910, h=0, pData=<value optimized out>, nDataSize=16, pDest=0x0, flag=1)
    at /app/php-5.4.8/Zend/zend_hash.c:385
#1  0x000000000068f600 in zend_list_insert (ptr=<value optimized out>, type=<value optimized out>) at /app/php-5.4.8/Zend/zend_list.c:46
#2  0x000000000068f61e in zend_register_resource (rsrc_result=0x0, rsrc_pointer=0x7ffff7fad2c8, rsrc_type=-134556984)
    at /app/php-5.4.8/Zend/zend_list.c:98
#3  0x00000000006392d6 in php_stream_context_alloc () at /app/php-5.4.8/main/streams/streams.c:2199
#4  0x0000000000455035 in php_libxml_streams_IO_open_wrapper (filename=0xea1990 "/app/libgda/share/libgda-4.0/dtd/libgda-array.dtd", 
    mode=0xa71434 "rb", read_only=1) at /app/php-5.4.8/ext/libxml/libxml.c:334
#5  0x000000000045509f in php_libxml_streams_IO_open_read_wrapper (URI=0x7ffff7fad2c8 "0\320\372\367\377\177", enc=XML_CHAR_ENCODING_NONE)
    at /app/php-5.4.8/ext/libxml/libxml.c:345
#6  php_libxml_input_buffer_create_filename (URI=0x7ffff7fad2c8 "0\320\372\367\377\177", enc=XML_CHAR_ENCODING_NONE)
    at /app/php-5.4.8/ext/libxml/libxml.c:386
#7  0x00007ffff6dc7d8d in xmlNewInputFromFile () from /usr/lib/libxml2.so.2
#8  0x000000000045681b in _php_libxml_pre_ext_ent_loader (URL=0xea1990 "/app/libgda/share/libgda-4.0/dtd/libgda-array.dtd", ID=0x0, 
    context=0xe9e0b0) at /app/php-5.4.8/ext/libxml/libxml.c:694
#9  0x00007ffff6e8d59b in xmlSAX2ResolveEntity () from /usr/lib/libxml2.so.2
#10 0x00007ffff6de35a5 in xmlSAXParseDTD () from /usr/lib/libxml2.so.2
#11 0x00007ffff5687307 in gda_init () at gda-init.c:198
#12 0x00007ffff610c249 in midgard_init () at src/midgard.c:138
#13 0x00007ffff639cb61 in zm_startup_midgard2 (type=1, module_number=28) at /app/midgard-php5-10.05.7/midgard.c:324

Steps from #11 to #8 clearly shows that php's hook is wrong in this case.
It doesn't happen with PHP 5.3, where global hook is not set.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-18 11:56 UTC] cataphract@php.net
I don't think that's the problem. Your frame #8:

#8  0x000000000045681b in _php_libxml_pre_ext_ent_loader (URL=0xea1990 "/app/libgda/share/libgda-4.0/dtd/libgda-array.dtd", ID=0x0, 
    context=0xe9e0b0) at /app/php-5.4.8/ext/libxml/libxml.c:694

indicates PHP is using the original entity loader:

694        return _php_libxml_default_entity_loader(URL, ID, context);

precisely because PHP refuses to use the custom entity loader except if all the modules have gone though module AND request init. _php_libxml_default_entity_loader is set here:

730PHP_LIBXML_API void php_libxml_initialize(void)
731{
732    if (!_php_libxml_initialized) {
733        /* we should be the only one's to ever init!! */
734        xmlInitParser();
735
736        _php_libxml_default_entity_loader = xmlGetExternalEntityLoader();
737        xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader);

So my guess is the problem is elsewhere. Namely, this commit:

https://github.com/php/php-src/commit/d8bddb966563

xmlParserInputBufferCreateFilenameDefault() is now called on module init and not on request init in some SAPIs. Other modules that use libxml but happen to run minit after the libxml PHP module may have some trouble as php_libxml_input_buffer_create_filename() may not be ready to be executed yet.
 [2013-01-18 12:08 UTC] cataphract@php.net
Can you patch the code so that _php_libxml_per_request_initialization is always 1 and see if that solves the problem?
 [2013-01-18 12:08 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2013-02-18 00:36 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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC