Skip to content

Fix GH-22825: DOM attribute methods on a DTD default attribute#22830

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22825-dom-dtd-default-attr
Closed

Fix GH-22825: DOM attribute methods on a DTD default attribute#22830
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-22825-dom-dtd-default-attr

Conversation

@iliaal

@iliaal iliaal commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

xmlHasNsProp() falls back to the internal subset, so on the legacy DOM an attribute lookup can return a DTD attribute declaration, and the switches over it never enumerated XML_ATTRIBUTE_DECL. EMPTY_SWITCH_DEFAULT_CASE compiles to __builtin_unreachable(), so instead of asserting, a release build silently returns false from setAttribute() and creates nothing. Any declaration carrying a default value hits this, not only #FIXED.

setAttribute() now creates the attribute as it did before 8.4. removeAttribute() returns false for a declaration, which is an observable change. The read-only callers are left for a separate report.

Fixes #22825

xmlHasNsProp() falls back to the internal subset, so the legacy ext/dom
attribute methods can receive a DTD attribute declaration instead of an
attribute node. setAttribute() and dom_remove_attribute() enumerated only
XML_ATTRIBUTE_NODE and XML_NAMESPACE_DECL, so a defaulted attribute
asserted on debug builds and ran into __builtin_unreachable() on release
builds, and setAttributeNode() skipped the declaration when unlinking the
old attribute but still returned it, throwing after the tree was already
modified. setAttribute() now creates the attribute as it did before 8.4,
matching setAttributeNS(); removeAttribute() reports that nothing was
removed, since the declaration lives in the DTD and not on the element;
setAttributeNode() returns null; and toggleAttribute() derives its result
from the removal instead of assuming it succeeded, so the returned value
keeps agreeing with hasAttribute(). getAttribute() and hasAttribute()
already handled the declaration, and the Dom\Element methods are
unaffected because the spec-compliant lookup never consults the DTD.

Fixes phpGH-22825
@iliaal iliaal closed this in 145e8c2 Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOMElement::setAttribute() reaches EMPTY_SWITCH_DEFAULT_CASE() with DTD #FIXED default attributes

2 participants