xmlpatterns_stack_overflow_fix
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Fri, 1 May 2015 19:35:39 +0000 (19:35 +0000)
committerLisandro Damián Nicanor Pérez Meyer <lisandro@debian.org>
Fri, 1 May 2015 19:35:39 +0000 (19:35 +0000)
commit d1b17740ed4d9b1e3c3ad5898bb8259969dc77df
Author: Kamil Rojewski <kamil.rojewski@gmail.com>
Date:   Wed Aug 13 10:38:38 2014 +0200

    fix for stack overflow

    Recursion in item mapping iterator caused a stack
    overflow for large datasets.

    Task-number: QTBUG-40153
    Change-Id: I693798de0ecfd3a920a3dd270172ce7ec3c13d8d
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Gbp-Pq: Name xmlpatterns_stack_overflow_fix.diff

src/xmlpatterns/iterators/qitemmappingiterator_p.h

index e2f19494b112e0f23c36f3ed037293280db70ff2..fd6046cd5a95d67b3e73c6e4b9e50fed1134fc39 100644 (file)
@@ -117,24 +117,28 @@ namespace QPatternist
          */
         virtual TResult next()
         {
-            const TSource sourceItem(m_it->next());
-
-            if(qIsForwardIteratorEnd(sourceItem))
-            {
-                m_current = TResult();
-                m_position = -1;
-                return TResult();
-            }
-            else
+            while (true)
             {
-                m_current = m_mapper->mapToItem(sourceItem, m_context);
-                if(qIsForwardIteratorEnd(m_current))
-                    return next(); /* The mapper returned null, so continue with the next in the source. */
-                else
+                const TSource &sourceItem = m_it->next();
+                if (qIsForwardIteratorEnd(sourceItem))
                 {
-                    ++m_position;
+                    m_current = TResult();
+                    m_position = -1;
                     return m_current;
                 }
+                else
+                {
+                    m_current = m_mapper->mapToItem(sourceItem, m_context);
+                    if (qIsForwardIteratorEnd(m_current))
+                    {
+                        continue; /* The mapper returned null, so continue with the next in the source. */
+                    }
+                    else
+                    {
+                        ++m_position;
+                        return m_current;
+                    }
+                }
             }
         }