Velocity
  1. Velocity
  2. VELOCITY-297

Maximum recursion depth for macro calls

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: All

      Description

      Similar to the option "directive.parse.maxdepth" I would love to see a parameter
      to limit the depth of macro call recursion. In my scenario I let simple users
      write macros to create html pages. Using recursive macros, they could get the
      application to misbehave.

      The following piece of code illustrates the problem:

      #macro ( showInfo $p )
      Info: $p
      #showInfo($p)
      #end
      #showInfo("Test")

      Which simply leads to:

      java.lang.StackOverflowError
      at
      org.apache.velocity.runtime.parser.node.ASTStringLiteral.value(ASTStringLiteral.java:136)
      at
      org.apache.velocity.runtime.directive.VMProxyArg.getObject(VMProxyArg.java:294)
      at org.apache.velocity.context.VMContext.get(VMContext.java:181)
      ....

      Current workaround: Disable inline macros. Have responsible Script-Developers.

      1. MacroMaxCallDepth.patch
        17 kB
        Supun Kamburugamuva

        Activity

        Jochen Toppe created issue -
        Jeff Turner made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 31563 12315167
        Hide
        Will Glass-Husain added a comment -

        Seems like a good idea. If you or someone else would like to contribute a patch, I'll commit it.

        Show
        Will Glass-Husain added a comment - Seems like a good idea. If you or someone else would like to contribute a patch, I'll commit it.
        Will Glass-Husain made changes -
        Assignee Velocity-Dev List [ velocity-dev@jakarta.apache.org ]
        Environment Operating System: All
        Platform: All
        Operating System: All
        Platform: All
        Bugzilla Id 31563
        Priority Major [ 3 ] Minor [ 4 ]
        Type Bug [ 1 ] Improvement [ 4 ]
        Description Similar to the option "directive.parse.maxdepth" I would love to see a parameter
        to limit the depth of macro call recursion. In my scenario I let simple users
        write macros to create html pages. Using recursive macros, they could get the
        application to misbehave.

        The following piece of code illustrates the problem:

        #macro ( showInfo $p )
          Info: $p
          #showInfo($p)
        #end
        #showInfo("Test")

        Which simply leads to:

        java.lang.StackOverflowError
                at
        org.apache.velocity.runtime.parser.node.ASTStringLiteral.value(ASTStringLiteral.java:136)
                at
        org.apache.velocity.runtime.directive.VMProxyArg.getObject(VMProxyArg.java:294)
                at org.apache.velocity.context.VMContext.get(VMContext.java:181)
           ....

        Current workaround: Disable inline macros. Have responsible Script-Developers.
        Similar to the option "directive.parse.maxdepth" I would love to see a parameter
        to limit the depth of macro call recursion. In my scenario I let simple users
        write macros to create html pages. Using recursive macros, they could get the
        application to misbehave.

        The following piece of code illustrates the problem:

        #macro ( showInfo $p )
          Info: $p
          #showInfo($p)
        #end
        #showInfo("Test")

        Which simply leads to:

        java.lang.StackOverflowError
                at
        org.apache.velocity.runtime.parser.node.ASTStringLiteral.value(ASTStringLiteral.java:136)
                at
        org.apache.velocity.runtime.directive.VMProxyArg.getObject(VMProxyArg.java:294)
                at org.apache.velocity.context.VMContext.get(VMContext.java:181)
           ....

        Current workaround: Disable inline macros. Have responsible Script-Developers.
        Will Glass-Husain made changes -
        Fix Version/s 1.6 [ 12310290 ]
        Bugzilla Id 31563
        Hide
        Henning Schmiedehausen added a comment -

        No news on the patch front. 1.6 it is, then.

        Show
        Henning Schmiedehausen added a comment - No news on the patch front. 1.6 it is, then.
        Henning Schmiedehausen made changes -
        Component/s Engine [ 12311337 ]
        Bugzilla Id 31563
        Component/s Source [ 12310214 ]
        Hide
        Supun Kamburugamuva added a comment -

        I have fixed this issue by giving the user the freedom to specify a max calling depth for macros as a property.

        Supun

        Show
        Supun Kamburugamuva added a comment - I have fixed this issue by giving the user the freedom to specify a max calling depth for macros as a property. Supun
        Supun Kamburugamuva made changes -
        Attachment MacroMaxCallDepth.patch [ 12359143 ]
        Hide
        Will Glass-Husain added a comment -

        committed patch. Made minor changes for JDK 1.4 compatibility and to preserve Directive API.

        Show
        Will Glass-Husain added a comment - committed patch. Made minor changes for JDK 1.4 compatibility and to preserve Directive API.
        Will Glass-Husain made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Mark Thomas made changes -
        Workflow jira [ 12325172 ] Default workflow, editable Closed status [ 12551248 ]
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551248 ] jira [ 12552180 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jochen Toppe
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development