Repository navigation
Conversation
Member
|
can the following test be added ? --TEST--
DOMNamedNodeMap iterator key() on an empty DTD named node map
--EXTENSIONS--
dom
--FILE--
<?php
$xml = '<!DOCTYPE root><root/>';
$doc = new DOMDocument();
$doc->loadXML($xml);
echo "DOMNamedNodeMap entities valid: ";
var_dump($doc->doctype->entities->getIterator()->valid());
echo "DOMNamedNodeMap entities key: ";
var_dump($doc->doctype->entities->getIterator()->key());
echo "DOMNamedNodeMap notations key: ";
var_dump($doc->doctype->notations->getIterator()->key());
$doc = Dom\XMLDocument::createFromString($xml);
echo "Dom\DtdNamedNodeMap entities valid: ";
var_dump($doc->doctype->entities->getIterator()->valid());
echo "Dom\DtdNamedNodeMap entities key: ";
var_dump($doc->doctype->entities->getIterator()->key());
echo "Dom\DtdNamedNodeMap notations key: ";
var_dump($doc->doctype->notations->getIterator()->key());
?>
--EXPECT--
DOMNamedNodeMap entities valid: bool(false)
DOMNamedNodeMap entities key: NULL
DOMNamedNodeMap notations key: NULL
Dom\DtdNamedNodeMap entities valid: bool(false)
Dom\DtdNamedNodeMap entities key: NULL
Dom\DtdNamedNodeMap notations key: NULL |
… item php_dom_iterator_current_key() read the object out of iterator->curobj for attribute and DTD named node maps without checking that the iterator has a current item. On an empty attribute map the object pointer is NULL and InternalIterator::key() crashes; once the iterator has moved past the last item it reads the wrapper move_forward() has already released. Return null in that case, as valid() and current() already treat an undefined curobj as the end. An entity or notation map of a DTD without an internal subset has no hash table and was keyed like a node list, returning int(0); select the name-keyed maps by node type instead, as move_forward() does. Integer-keyed node lists are unaffected.
iliaal
force-pushed
the
fix/dom-iterator-key
branch
from
November 20, 2026 23:38
9b8724d to
9746e29
Compare
Member
Author
|
Added. It caught a second case: a DTD without an internal subset has no entity or notation hash table, so key() took the node-list branch and returned int(0). Switched the check to the node type. |
devnexen
approved these changes
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
key() on the iterator of an attribute or DTD named node map reads the current item's object without checking that there is one, so it segfaults on an empty map, such as the attributes of
<root/>, and reads a released wrapper once next() has moved past the last item. Return null in that case, as valid() and current() already treat it as the end. The entity and notation maps of a DTD without an internal subset have no hash table and were keyed like a node list, returning int(0) instead of null, so select the name-keyed maps by node type instead.