Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-18650

Formula macro infinite loop blocking all other pages with formulas

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 12.10.6
    • Formula
    • None
    • Unknown

    Description

      The following type of content:

      content before
      {{formula}}V_c=\sqrt{{2 g}\cdot{(H_{am} - Y_c})}{{/formula}}
      !!!this should not be part of the formula!!!
      

      Renders as:

      Suggests that the current handling of the formula macro makes it extremely fragile and prone to human error. The error is actually a typo at the end of the formula, instead of })}, it should have been )}}

      In my case, the document content was large and followed by many other formulas. The rendering of the FormulaMacro was looping infinitely, with a stacktrace similar to:

         java.lang.Thread.State: RUNNABLE
              at org.apache.batik.dom.AbstractParentNode$ChildNodes.item(AbstractParentNode.java:751)
              at net.sourceforge.jeuclid.elements.AbstractJEuclidElement.getIndexOfMathElement(AbstractJEuclidElement.java:387)
              at net.sourceforge.jeuclid.elements.presentation.token.Mo.detectFormParameter(Mo.java:360)
              at net.sourceforge.jeuclid.elements.presentation.token.Mo.changeHook(Mo.java:297)
              at net.sourceforge.jeuclid.elements.presentation.token.Mo.handleEvent(Mo.java:734)
              at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:320)
              at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:362)
              at org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:273)
              at org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1012)
              at net.sourceforge.jeuclid.elements.AbstractJEuclidElement.dispatchEvent(AbstractJEuclidElement.java:876)
              at org.apache.batik.dom.AbstractParentNode.fireDOMSubtreeModifiedEvent(AbstractParentNode.java:400)
              at org.apache.batik.dom.AbstractParentNode.appendChild(AbstractParentNode.java:225)
              at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.appendTextNode(SAX2DOM.java:128)
              at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.endElement(SAX2DOM.java:230)
              at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:263)
              at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:557)
              at die.verwandlung.GregorSamsa.template$dot$0()
              at die.verwandlung.GregorSamsa.applyTemplates()
              at die.verwandlung.GregorSamsa.template$dot$0()
              at die.verwandlung.GregorSamsa.applyTemplates()
              at die.verwandlung.GregorSamsa.template$dot$0()
              at die.verwandlung.GregorSamsa.applyTemplates()
              at die.verwandlung.GregorSamsa.template$dot$0()
              at die.verwandlung.GregorSamsa.applyTemplates()
              at die.verwandlung.GregorSamsa.applyTemplates()
              at die.verwandlung.GregorSamsa.transform()
              at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:624)
              at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:776)
              at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:370)
              at net.sourceforge.jeuclid.DOMBuilder.applyTransform(DOMBuilder.java:217)
              - locked on com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl@2779cfae
              at net.sourceforge.jeuclid.DOMBuilder.createJeuclidDom(DOMBuilder.java:196)
              at net.sourceforge.jeuclid.layout.JEuclidView.<init>(JEuclidView.java:86)
              at net.sourceforge.jeuclid.converter.Converter.render(Converter.java:326)
              at net.sourceforge.jeuclid.converter.ImageIOConverter.convert(ImageIOConverter.java:67)
              at net.sourceforge.jeuclid.converter.Converter.convert(Converter.java:246)
              at uk.ac.ed.ph.snuggletex.jeuclid.JEuclidMathMLPostProcessor.handleMathMLIsland(JEuclidMathMLPostProcessor.java:68)
              at uk.ac.ed.ph.snuggletex.utilities.MathMLPostProcessor$DocumentWalker.run(MathMLPostProcessor.java:70)
              at uk.ac.ed.ph.snuggletex.utilities.MathMLPostProcessor.postProcessDOM(MathMLPostProcessor.java:28)
              at uk.ac.ed.ph.snuggletex.internal.DOMBuildingController.buildDOMSubtree(DOMBuildingController.java:60)
              at uk.ac.ed.ph.snuggletex.internal.WebPageBuilder.buildWebPage(WebPageBuilder.java:85)
              at uk.ac.ed.ph.snuggletex.internal.WebPageBuilder.writeWebPage(WebPageBuilder.java:297)
              at uk.ac.ed.ph.snuggletex.SnuggleSession.writeWebPage(SnuggleSession.java:600)
              at uk.ac.ed.ph.snuggletex.SnuggleSession.writeWebPage(SnuggleSession.java:527)
              at org.xwiki.formula.internal.SnuggleTexFormulaRenderer.renderImage(SnuggleTexFormulaRenderer.java:79)
              at org.xwiki.formula.AbstractFormulaRenderer.process(AbstractFormulaRenderer.java:55)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.render(FormulaMacro.java:156)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.execute(FormulaMacro.java:119)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.execute(FormulaMacro.java:57)
              at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
              at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
              at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:103)
              at org.xwiki.display.internal.DocumentContentAsyncExecutor.executeInCurrentExecutionContext(DocumentContentAsyncExecutor.java:348)
              at org.xwiki.display.internal.DocumentContentAsyncExecutor.execute(DocumentContentAsyncExecutor.java:221)
              at org.xwiki.display.internal.DocumentContentAsyncRenderer.execute(DocumentContentAsyncRenderer.java:107)
              at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
              at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
              at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:273)
              at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
              at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
              at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:67)
              at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:43)
              at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
              at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
              at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:123)
              at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:52)
              at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
              at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
              at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:1216)
              at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1357)
              at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1306)
              at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1273)
              at com.xpn.xwiki.api.Document.displayDocument(Document.java:786)
              at jdk.internal.reflect.GeneratedMethodAccessor574.invoke()
              at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      ...
      

      The lock held by this thread - locked on com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl@2779cfae was then causing all other several threads that were trying to render a FormulaMacro to be blocked:

         java.lang.Thread.State: BLOCKED
              at net.sourceforge.jeuclid.DOMBuilder.applyTransform(DOMBuilder.java:216)
              - waiting to lock com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl@2779cfae
              at net.sourceforge.jeuclid.DOMBuilder.createJeuclidDom(DOMBuilder.java:196)
              at net.sourceforge.jeuclid.layout.JEuclidView.<init>(JEuclidView.java:86)
              at net.sourceforge.jeuclid.converter.Converter.render(Converter.java:326)
              at net.sourceforge.jeuclid.converter.ImageIOConverter.convert(ImageIOConverter.java:67)
              at net.sourceforge.jeuclid.converter.Converter.convert(Converter.java:246)
              at uk.ac.ed.ph.snuggletex.jeuclid.JEuclidMathMLPostProcessor.handleMathMLIsland(JEuclidMathMLPostProcessor.java:68)
              at uk.ac.ed.ph.snuggletex.utilities.MathMLPostProcessor$DocumentWalker.run(MathMLPostProcessor.java:70)
              at uk.ac.ed.ph.snuggletex.utilities.MathMLPostProcessor.postProcessDOM(MathMLPostProcessor.java:28)
              at uk.ac.ed.ph.snuggletex.internal.DOMBuildingController.buildDOMSubtree(DOMBuildingController.java:60)
              at uk.ac.ed.ph.snuggletex.internal.WebPageBuilder.buildWebPage(WebPageBuilder.java:85)
              at uk.ac.ed.ph.snuggletex.internal.WebPageBuilder.writeWebPage(WebPageBuilder.java:297)
              at uk.ac.ed.ph.snuggletex.SnuggleSession.writeWebPage(SnuggleSession.java:600)
              at uk.ac.ed.ph.snuggletex.SnuggleSession.writeWebPage(SnuggleSession.java:527)
              at org.xwiki.formula.internal.SnuggleTexFormulaRenderer.renderImage(SnuggleTexFormulaRenderer.java:79)
              at org.xwiki.formula.AbstractFormulaRenderer.process(AbstractFormulaRenderer.java:55)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.render(FormulaMacro.java:156)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.execute(FormulaMacro.java:119)
              at org.xwiki.rendering.internal.macro.formula.FormulaMacro.execute(FormulaMacro.java:57)
              at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
              at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
              at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:103)
              at org.xwiki.display.internal.DocumentContentAsyncExecutor.executeInCurrentExecutionContext(DocumentContentAsyncExecutor.java:348)
              at org.xwiki.display.internal.DocumentContentAsyncExecutor.execute(DocumentContentAsyncExecutor.java:221)
              at org.xwiki.display.internal.DocumentContentAsyncRenderer.execute(DocumentContentAsyncRenderer.java:107)
              at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
              at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
              at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:273)
              at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
              at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
              at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:67)
              at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:43)
              at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
              at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
              at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:123)
              at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:52)
              at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
              at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
              at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:1216)
              at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1357)
              at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1306)
              at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1273)
              at com.xpn.xwiki.api.Document.displayDocument(Document.java:786)
              at jdk.internal.reflect.GeneratedMethodAccessor574.invoke()
              at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      ...
      

      So we seem to have 2 big problems:
      1. The parsing/escaping issue that allows invalid formula content to easily spill in wiki content from the rest of the document
      2. The fact that the formula rendering seems to be sequential, rendering 1 formula at a time for all rendering threads, which is a big scalability bottleneck.

      Attachments

        Activity

          People

            Unassigned Unassigned
            enygma Eduard Moraru
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: