php.net |  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
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: phpbug at drque dot net
New email:
PHP Version: OS:

 

 [2006-06-14 21:30 UTC] phpbug at drque dot net
Description:
------------
Tricky bug: if you run the example, you get a segmentation fault.  If you change the line:
  $Data = $body->appendChild( $dom->createElement( 'Data', '123' ) );
to
  $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:
---------------
<?php

// 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"?>
<Body>
  <Data>2</Data>
</Body>


Actual result:
--------------
Segmentation fault

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-14 23:30 UTC] rrichards@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC