[libxslt] Fix quadratic behavior with variables and parameters



commit 774765ad37c31885f47ef8b964392f7f32decdaf
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Jun 6 14:01:46 2022 +0200

    Fix quadratic behavior with variables and parameters
    
    Backup and restore "lasttext" state when evaluating variables or
    template parameters. Otherwise, appending multiple text nodes would
    lead to quadratic behavior.
    
    Fixes #70.

 libxslt/variables.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/libxslt/variables.c b/libxslt/variables.c
index 03082700..60341d55 100644
--- a/libxslt/variables.c
+++ b/libxslt/variables.c
@@ -963,6 +963,8 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr variable,
                xmlDocPtr container;
                xmlNodePtr oldInsert;
                xmlDocPtr  oldOutput;
+                const xmlChar *oldLastText;
+                int oldLastTextSize, oldLastTextUse;
                xsltStackElemPtr oldVar = ctxt->contextVariable;
 
                /*
@@ -988,6 +990,9 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr variable,
 
                oldOutput = ctxt->output;
                oldInsert = ctxt->insert;
+                oldLastText = ctxt->lasttext;
+                oldLastTextSize = ctxt->lasttsize;
+                oldLastTextUse = ctxt->lasttuse;
 
                ctxt->output = container;
                ctxt->insert = (xmlNodePtr) container;
@@ -1002,6 +1007,9 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr variable,
                ctxt->contextVariable = oldVar;
                ctxt->insert = oldInsert;
                ctxt->output = oldOutput;
+                ctxt->lasttext = oldLastText;
+                ctxt->lasttsize = oldLastTextSize;
+                ctxt->lasttuse = oldLastTextUse;
 
                result = xmlXPathNewValueTree((xmlNodePtr) container);
            }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]