Commit 47344051 authored by Michael Reeves's avatar Michael Reeves

Avoid ranaway allocation

Revert broken check for matching starting characters.
Add emergancy back stop in calcDiff  to main loop. We should never reach
this condition. However we must garentee this code never goes into an
infenite loop regardlless of any pontental bug or unexepected input.

BUG: 410007
FIXED-IN:1.8.2
parent 7c011096
...@@ -1167,10 +1167,15 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in ...@@ -1167,10 +1167,15 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in
QString::const_iterator p1=line1.begin(), p2=line2.begin(); QString::const_iterator p1=line1.begin(), p2=line2.begin();
for(;;) /*
This loop should never reach the exit condition specified here. However it must have a hard wired
stopping point to prevent runaway allocation if something unexpected happens.
diffList is therefor hard capped at aprox 50 MB in size.
*/
for(; diffList.size() * sizeof(Diff) + sizeof(DiffList) < (50 << 20);)
{ {
int nofEquals = 0; int nofEquals = 0;
while(nofEquals < line1.size() && nofEquals < line2.size() && line1[nofEquals] == line2[nofEquals]) while(p1 != line1.end() && p2 != line2.end() && *p1 == *p2)
{ {
++p1; ++p1;
++p2; ++p2;
...@@ -1223,6 +1228,7 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in ...@@ -1223,6 +1228,7 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in
{ {
// continue somehow // continue somehow
Diff d(nofEquals, bestI1, bestI2); Diff d(nofEquals, bestI1, bestI2);
Q_ASSERT(nofEquals + bestI1 + bestI2 != 0);
diffList.push_back(d); diffList.push_back(d);
p1 += bestI1; p1 += bestI1;
...@@ -1301,6 +1307,8 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in ...@@ -1301,6 +1307,8 @@ void calcDiff(const QString& line1, const QString& line2, DiffList& diffList, in
break; break;
} }
Q_ASSERT(diffList.size() * sizeof(Diff) + sizeof(DiffList) >= (50 << 20));
// Verify difflist // Verify difflist
{ {
qint32 l1 = 0; qint32 l1 = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment