Bug 872971 - Clamp regexp quantifiers to INT_MAX. r=jandem

This commit is contained in:
Till Schneidereit 2013-12-18 16:45:26 +01:00
parent bb2550d1e4
commit b118028370
2 changed files with 16 additions and 0 deletions

View File

@ -10,3 +10,8 @@ reportCompare(["a", ""].toSource(), toSource(/((?:.)*?)a/.exec("a")));
reportCompare(["a", ""].toSource(), toSource(/a((?:.)*)/.exec("a")));
reportCompare(["B", "B"].toSource(), toSource(/([A-Z])/.exec("fooBar")));
// These just mustn't crash. See bug 872971
reportCompare(/x{2147483648}x/.test('1'), false);
reportCompare(/x{2147483648,}x/.test('1'), false);
reportCompare(/x{2147483647,2147483648}x/.test('1'), false);

View File

@ -612,12 +612,23 @@ private:
unsigned min;
if (!consumeNumber(min))
break;
// Clamping to INT_MAX is technically a spec deviation. In practice, it's
// undetectable, because we can't even allocate strings large enough for
// quantifiers this large to ever create different results than smaller ones.
if (min > INT_MAX)
min = INT_MAX;
unsigned max = min;
if (tryConsume(',')) {
if (peekIsDigit()) {
if (!consumeNumber(max))
break;
// Clamping to INT_MAX is technically a spec deviation. In practice,
// it's undetectable, because we can't even allocate strings large
// enough for quantifiers this large to ever create different results
// than smaller ones.
if (max > INT_MAX)
max = INT_MAX;
} else {
max = quantifyInfinite;
}