php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14717 crash while trying to call DOM XML from SAX handlers
Submitted: 2001-12-27 06:52 UTC Modified: 2001-12-28 21:08 UTC
From: flying at dom dot natm dot ru Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.0.6 OS: Windows 2000, Windows NT
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: flying at dom dot natm dot ru
New email:
PHP Version: OS:

 

 [2001-12-27 06:52 UTC] flying at dom dot natm dot ru
Envionment:
 - Windows 2000 server or Windows NT 4.0 SP6
 - Apache 1.3.20 or 1.3.22
 - PHP v4.0.6 (windows binaries from www.php.net) running as CGI

 i'm trying to parse XML file by using expat and insert parts of it into DOM XML tree, i have. But PHP crashes, because of reading memory at address 0x00000000. This bug is 100% reproducible with test case, listed below on 2 different machines.

 Here is test case:

file test.php:
-------------------------------------------------------
<?php
function startElement($parser,$name,$attrs)
{
    global $path,$curPath,$curNode;

    $curPath .= '/'.$name;
    if (preg_match($path,$curPath))
        $curNode = $curNode->new_child($name,null);
};

function endElement($parser,$name)
{
    global $path,$curPath,$curNode;

    $pathName = substr($curPath,strrpos($curPath,'/')+1);
    $curPath = substr($curPath,0,strrpos($curPath,'/'));
    if (($name==$pathName) && ($name==$curNode->name))
        $curNode = $curNode->parent();
};

$path = '|^/root/news(/.+)?$|';
$curPath = '';

$xmlStr = join('',file('file1.xml'));
$xml = xmldoc($xmlStr);
$curNode = $xml->root();
$xmlStr = join('',file('file2.xml'));
$parser = xml_parser_create();
xml_set_element_handler($parser,'startElement','endElement');
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,false);
xml_parse($parser,$xmlStr,true);
xml_parser_free($parser);

echo htmlspecialchars($xml->dumpmem());
?>
-------------------------------------------------------

file file1.xml:
-------------------------------------------------------
<?xml version="1.0"?>
<root>
    <node>
        <child id="1"/>
        <child id="2"/>
        <child id="3"/>
    </node>
</root>
-------------------------------------------------------

file file2.xml:
-------------------------------------------------------
<?xml version="1.0"?>
<root>
    <news>
        <item id="1"/>
        <item id="2"/>
        <item id="3"/>
    </news>
    <products>
        <product id="1"/>
        <product id="2"/>
        <product id="3"/>
    </products>
</root>
-------------------------------------------------------

 PHP crashing can be avoided in two cases:
1. By removing lines, related to work with DOM XML:
        $curNode = $curNode->new_child($name,null);
        $curNode = $curNode->parent();

2. By removing regular expression matching:
    if (preg_match($path,$curPath))

 Switching from preg_match() to ereg() give the same crash.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-27 06:54 UTC] sander@php.net
Please upgrade to the latest version (4.1.0 should do, 4.1.1 is even better). Does the problem still exists?
 [2001-12-27 12:47 UTC] flying at dom dot natm dot ru
Test case, listed above, works well into PHP v4.1.0.

This bug can be closed.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 13:01:28 2024 UTC