Repository navigation
Conversation
ae17964 to
d6ef752
Compare
|
do not know if this PR is in fact ready but the source tree is not read-only for a transformation started by another processor: php_xsl_apply_stylesheet() raises read_only_depth but never checks it, so a callback running a second XSLTProcessor with xsl:strip-space on the same document lets libxslt free whitespace text nodes the outer transformation still uses (ASAN heap-use-after-free in xsltApplyStripSpaces). can the transformation be refused when the source document is read-only and not copied ? doXInclude looks like the same case. |
d6ef752 to
77c13ae
Compare
|
The check is in the ext/dom commit from GH-25357, which this branch carries: |
php_xsl_apply_stylesheet() keeps the transformation's document reference in intern->doc and the callback node wrappers in the processor's node list, so a second transformation on the same processor, started from a php:function() callback or from main code while a Fiber is suspended inside one, freed that state under the running transformation. Throw an Error for such a call, as importStylesheet() already does.
A php:function() callback runs while libxml2 builds an XPath node-set, so modifying the tree or dropping the last reference to a detached subtree freed nodes the evaluation still referenced. While DOMXPath or Dom\XPath evaluates with PHP functions registered, the tree of the evaluated document, the tree of every node a callback returned and the detached subtrees of the context node and of callback arguments are read-only: modifying them throws a DOMException with NO_MODIFICATION_ALLOWED_ERR or, through SimpleXML, an Error, and the evaluation keeps those subtrees alive until it ends. New nodes and document properties stay modifiable. XSLTProcessor refuses to transform a read-only document in place, because libxslt frees whitespace text nodes of its source for xsl:strip-space.
… document A php:function() callback, or an entity loader or error handler, runs while libxslt walks the source tree, so modifying the tree or dropping the last reference to a detached subtree freed nodes the transformation still referenced. Make the source tree read-only for the duration of every transformation, and arm the XPath callback registry so that, as for DOMXPath, the trees of returned nodes and the detached subtrees of the current node and of callback arguments are read-only and kept alive until the transformation ends.
77c13ae to
f9bf8d6
Compare
Depends on #25355 and #25357, whose commits this branch carries.
A php:function() callback, entity loader or error handler runs while libxslt walks the source tree, so modifying that tree frees nodes the transformation still uses. Make the source tree read-only for every transformation, and protect callback-returned and detached trees as #25357 does for DOMXPath. ext/xsl/tests/bug69168.phpt and cloneDocument.phpt change because their callbacks modified the source document; setting cloneDocument to true keeps the original modifiable.