php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71571 XSLT processor should provide option to change maxDepth
Submitted: 2016-02-11 15:59 UTC Modified: 2024-03-31 19:21 UTC
Votes:5
Avg. Score:4.2 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: sam dot marshall at open dot ac dot uk Assigned: nielsdos (profile)
Status: Closed Package: XSLT related
PHP Version: 7.0.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 4 = ?
Subscribe to this entry?

 
 [2016-02-11 15:59 UTC] sam dot marshall at open dot ac dot uk
Description:
------------
The libxslt XSLT processor has a recursion depth limit, which appears to be different in different versions. (I briefly looked at the libxslt source and couldn't find this change so it might depend on the operating system and/or PHP version, or specific OS configuration.)

The provided test script demonstrates the recursion limit in practice; the script will print out lots of numbers before ending with an error, and the recursion limit is the last number + 1. Here are some examples from three different systems:

PHP 5.4.36 RHEL 5, libxslt 1.1.17: limit is 12,500
PHP 5.4.40 RHEL 7, libxslt 1.1.28: limit is 3,000
PHP 7.0.3 Mac, libxslt 1.1.28: limit is 3,000

When you hit the recursion limit, you see the following information in the PHP warnings that appear:

Warning: XSLTProcessor::transformToDoc(): runtime error: [...]
Warning: XSLTProcessor::transformToDoc(): xsltApplyXSLTTemplate: A potential infinite template recursion was detected.
You can adjust xsltMaxDepth (--maxdepth) in order to raise the maximum number of nested template calls and variables/params (currently set to 3000). in [...]

This is a helpful message and if using the command-line xsltproc or the C library, I believe it's possible to adjust that maximum number exactly as it says. However, there is currently no way to change the maxdepth parameter from PHP.

So the change request: It would be nice if there were a php.ini parameter, or a way to set this on the XSLTProcessor instance, or something similar, so that this value could be increased.

For background: when using pure XSLT it is often necessary to create heavily recursive code, so the 3,000 limit is actually not completely unreasonable (although it does probably indicate that your code could do with a rewrite - in the case where I actually experienced this problem, I was able to resolve it by changing the XSLT, but it would be good to have the option of changing the parameter).

Test script:
---------------
http://pastebin.com/B0rRaRH2


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-17 16:54 UTC] cmb@php.net
Doesn't appear to be hard to support this feature; the
::transform*() methods could take an additional optional
parameter, and we would have to assign its value to the respective
maxTemplateDepth member of struct _xsltTransformContext[1].

[1] <https://github.com/php/php-src/blob/php-7.4.16/ext/xsl/xsltprocessor.c#L532>
 [2023-09-30 14:22 UTC] nielsdos@php.net
-Status: Open +Status: Verified
 [2024-03-31 19:21 UTC] nielsdos@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nielsdos
 [2024-03-31 19:21 UTC] nielsdos@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Implemented in PHP 8.4.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 12:01:31 2024 UTC