Work around C14N duplicate xmlns bug on libxml 2.9.14#101
Merged
Conversation
C14N() on DOM-manipulated documents produces duplicate xmlns declarations when the element has a default xmlns and non-xmlns attributes (e.g. after optimize_namespaces). On libxml 2.9.14, parsing the invalid output hangs or crashes with double free. Fixes: - canonicalize(): round-trip through saveXml before C14N to normalize namespace declarations - rename_element_namespace(): remove stray Attr::rename() call that ran on a detached attribute node after removeAttributeNode()
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.
Summary
canonicalize(): round-trip throughsaveXml()before callingC14N()to normalize namespace declarations that get corrupted in DOM-manipulated documentsrename_element_namespace(): remove strayAttr::rename()call that ran on a detached attribute node afterremoveAttributeNode()Problem
C14N()on DOM-manipulated documents (e.g. afteroptimize_namespaces()) produces duplicate xmlns declarations when the element has a default xmlns and non-xmlns attributes. On libxml 2.9.14 (Ubuntu 24.04), parsing the invalid C14N output hangs or crashes withdouble free.Minimal reproducer:
This caused
comparable()(which callsoptimize_namespaces()thencanonicalize()) to hang on CI with libxml 2.9.14.Test plan
CanonicalizeTest::test_it_can_canonicalize_after_dom_manipulationpassesComparableTestdata casedefault-xmlns-with-attributespassesdocphpro/php84)