|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37809 DOM Segmentation fault when changing "firstChild->data"
Submitted: 2006-06-14 21:30 UTC Modified: 2006-06-14 23:30 UTC
From: phpbug at drque dot net Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.1.4 OS: Linux; Debian kernel 2.6.8-3-k7
Private report: No CVE-ID: None
 [2006-06-14 21:30 UTC] phpbug at drque dot net
Tricky bug: if you run the example, you get a segmentation fault.  If you change the line:
  $Data = $body->appendChild( $dom->createElement( 'Data', '123' ) );
  $Data = $body->appendChild( $dom->createElement( 'Data', '1234' ) );

The script executes as expected.  It seems that as long as the data in the field is 4 characters or more, everything runs as expected.  However, if the data is less then 4 characters, attempting to change it causes a segmentation fault, every time.

I've tried this code and get the error with versions 5.1.3, 5.1.4 and the 6/14/2006 snapshot of 6.0.0.

Reproduce code:

// Create some XML
$dom = new DOMDocument('1.0');
$dom->formatOutput = true;
$body = $dom->appendChild( $dom->createElement( 'Body' ) );
$Data = $body->appendChild( $dom->createElement( 'Data', '123' ) );
$dom->save( 'Data.xml' );

// Atempt to load and change XML file
$NewDOM = new DOMDocument('1.0');
$NewDOM->load( 'Data.xml' );

$Data = $NewDOM->getElementsByTagName( 'Data' )->item( 0 );
$Data->firstChild->data = 2;
$NewDOM->save( 'Data.xml' );


Expected result:
Data.xml should be:
<?xml version="1.0"?>

Actual result:
Segmentation fault


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-14 23:30 UTC]
This appears to be a libxml bug that has been fixed in newer releases. Either use a newer version (.21 or later) or as a workaround remove text node and append a new one with new value (or just replaceChild).
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jul 04 19:01:16 2020 UTC