Skip to content

DOM\XMLDocument::createComment() triggers undefined behavior with null byte #18979

Closed

Description

@bendrissou

Description

The following code:

<?php
$dom = DOM\XMLDocument::createEmpty();

function createContainer() {
    global $dom;
$element = $dom->createElement("container");
    return $element;
}
$container = createContainer();
$container->append($dom->createComment("^@ is -a- comment")); // contains null byte \x00
var_dump($container->innerHTML);
?>

Resulted in this output:

/home/program/ext/dom/xml_serializer.c:643:52: runtime error: addition of unsigned offset to 0x602000002b50 overflowed to 0x602000002b4f
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/program/ext/dom/xml_serializer.c:643:52 in 

But I expected this output instead:

string(22) "<!-- is -a- comment-->"

PHP Version

PHP 8.5.0-dev (cli) (built: Jun  4 2025 20:21:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.0-dev, Copyright (c) Zend Technologies

Operating System

Ubuntu 20.04

Activity

  1. added a commit that references this issue on Jun 30, 2025
    f98231b
  2. self-assigned this
    on Jun 30, 2025
  3. added 2 commits that reference this issue on Jul 1, 2025
    30662e4
    1d5089e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions