Commit d1f68f77 authored by yangguo's avatar yangguo Committed by Commit bot

[regexp] fix bogus assertion in CharacterRange constructor.

The CharacterRange constructor checks the input for validity. However,
CharacterRange::Singleton also uses the constructor and may have
kEndMarker as input, causing the check to fail.

The solution is to move the check to CharacterRange::Range and
consistently use it across the code base.

R=jkummerow@chromium.org
BUG=chromium:593282
LOG=N

Review URL: https://codereview.chromium.org/1776013003

Cr-Commit-Position: refs/heads/master@{#34626}
parent 592ad6dc
...@@ -4901,16 +4901,18 @@ UnicodeRangeSplitter::UnicodeRangeSplitter(Zone* zone, ...@@ -4901,16 +4901,18 @@ UnicodeRangeSplitter::UnicodeRangeSplitter(Zone* zone,
table_.AddRange(base->at(i), kBase, zone_); table_.AddRange(base->at(i), kBase, zone_);
} }
// Add overlay ranges. // Add overlay ranges.
table_.AddRange(CharacterRange(0, kLeadSurrogateStart - 1), kBmpCodePoints, table_.AddRange(CharacterRange::Range(0, kLeadSurrogateStart - 1),
zone_);
table_.AddRange(CharacterRange(kLeadSurrogateStart, kLeadSurrogateEnd),
kLeadSurrogates, zone_);
table_.AddRange(CharacterRange(kTrailSurrogateStart, kTrailSurrogateEnd),
kTrailSurrogates, zone_);
table_.AddRange(CharacterRange(kTrailSurrogateEnd + 1, kNonBmpStart - 1),
kBmpCodePoints, zone_); kBmpCodePoints, zone_);
table_.AddRange(CharacterRange(kNonBmpStart, kNonBmpEnd), kNonBmpCodePoints, table_.AddRange(CharacterRange::Range(kLeadSurrogateStart, kLeadSurrogateEnd),
zone_); kLeadSurrogates, zone_);
table_.AddRange(
CharacterRange::Range(kTrailSurrogateStart, kTrailSurrogateEnd),
kTrailSurrogates, zone_);
table_.AddRange(
CharacterRange::Range(kTrailSurrogateEnd + 1, kNonBmpStart - 1),
kBmpCodePoints, zone_);
table_.AddRange(CharacterRange::Range(kNonBmpStart, kNonBmpEnd),
kNonBmpCodePoints, zone_);
table_.ForEach(this); table_.ForEach(this);
} }
...@@ -5797,7 +5799,7 @@ static void AddClass(const int* elmv, ...@@ -5797,7 +5799,7 @@ static void AddClass(const int* elmv,
DCHECK(elmv[elmc] == kRangeEndMarker); DCHECK(elmv[elmc] == kRangeEndMarker);
for (int i = 0; i < elmc; i += 2) { for (int i = 0; i < elmc; i += 2) {
DCHECK(elmv[i] < elmv[i + 1]); DCHECK(elmv[i] < elmv[i + 1]);
ranges->Add(CharacterRange(elmv[i], elmv[i + 1] - 1), zone); ranges->Add(CharacterRange::Range(elmv[i], elmv[i + 1] - 1), zone);
} }
} }
...@@ -5814,10 +5816,10 @@ static void AddClassNegated(const int *elmv, ...@@ -5814,10 +5816,10 @@ static void AddClassNegated(const int *elmv,
for (int i = 0; i < elmc; i += 2) { for (int i = 0; i < elmc; i += 2) {
DCHECK(last <= elmv[i] - 1); DCHECK(last <= elmv[i] - 1);
DCHECK(elmv[i] < elmv[i + 1]); DCHECK(elmv[i] < elmv[i + 1]);
ranges->Add(CharacterRange(last, elmv[i] - 1), zone); ranges->Add(CharacterRange::Range(last, elmv[i] - 1), zone);
last = elmv[i + 1]; last = elmv[i + 1];
} }
ranges->Add(CharacterRange(last, String::kMaxCodePoint), zone); ranges->Add(CharacterRange::Range(last, String::kMaxCodePoint), zone);
} }
...@@ -5935,7 +5937,7 @@ void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone, ...@@ -5935,7 +5937,7 @@ void CharacterRange::AddCaseEquivalents(Isolate* isolate, Zone* zone,
uc32 range_from = c - (block_end - pos); uc32 range_from = c - (block_end - pos);
uc32 range_to = c - (block_end - end); uc32 range_to = c - (block_end - end);
if (!(bottom <= range_from && range_to <= top)) { if (!(bottom <= range_from && range_to <= top)) {
ranges->Add(CharacterRange(range_from, range_to), zone); ranges->Add(CharacterRange::Range(range_from, range_to), zone);
} }
} }
pos = end + 1; pos = end + 1;
...@@ -6029,7 +6031,7 @@ static int InsertRangeInCanonicalList(ZoneList<CharacterRange>* list, ...@@ -6029,7 +6031,7 @@ static int InsertRangeInCanonicalList(ZoneList<CharacterRange>* list,
CharacterRange to_replace = list->at(start_pos); CharacterRange to_replace = list->at(start_pos);
int new_from = Min(to_replace.from(), from); int new_from = Min(to_replace.from(), from);
int new_to = Max(to_replace.to(), to); int new_to = Max(to_replace.to(), to);
list->at(start_pos) = CharacterRange(new_from, new_to); list->at(start_pos) = CharacterRange::Range(new_from, new_to);
return count; return count;
} }
// Replace a number of existing ranges from start_pos to end_pos - 1. // Replace a number of existing ranges from start_pos to end_pos - 1.
...@@ -6040,7 +6042,7 @@ static int InsertRangeInCanonicalList(ZoneList<CharacterRange>* list, ...@@ -6040,7 +6042,7 @@ static int InsertRangeInCanonicalList(ZoneList<CharacterRange>* list,
if (end_pos < count) { if (end_pos < count) {
MoveRanges(list, end_pos, start_pos + 1, count - end_pos); MoveRanges(list, end_pos, start_pos + 1, count - end_pos);
} }
list->at(start_pos) = CharacterRange(new_from, new_to); list->at(start_pos) = CharacterRange::Range(new_from, new_to);
return count - (end_pos - start_pos) + 1; return count - (end_pos - start_pos) + 1;
} }
...@@ -6104,12 +6106,13 @@ void CharacterRange::Negate(ZoneList<CharacterRange>* ranges, ...@@ -6104,12 +6106,13 @@ void CharacterRange::Negate(ZoneList<CharacterRange>* ranges,
} }
while (i < range_count) { while (i < range_count) {
CharacterRange range = ranges->at(i); CharacterRange range = ranges->at(i);
negated_ranges->Add(CharacterRange(from, range.from() - 1), zone); negated_ranges->Add(CharacterRange::Range(from, range.from() - 1), zone);
from = range.to() + 1; from = range.to() + 1;
i++; i++;
} }
if (from < String::kMaxCodePoint) { if (from < String::kMaxCodePoint) {
negated_ranges->Add(CharacterRange(from, String::kMaxCodePoint), zone); negated_ranges->Add(CharacterRange::Range(from, String::kMaxCodePoint),
zone);
} }
} }
...@@ -6188,8 +6191,9 @@ void DispatchTable::AddRange(CharacterRange full_range, int value, ...@@ -6188,8 +6191,9 @@ void DispatchTable::AddRange(CharacterRange full_range, int value,
if (entry->from() < current.from() && entry->to() >= current.from()) { if (entry->from() < current.from() && entry->to() >= current.from()) {
// Snap the overlapping range in half around the start point of // Snap the overlapping range in half around the start point of
// the range we're adding. // the range we're adding.
CharacterRange left(entry->from(), current.from() - 1); CharacterRange left =
CharacterRange right(current.from(), entry->to()); CharacterRange::Range(entry->from(), current.from() - 1);
CharacterRange right = CharacterRange::Range(current.from(), entry->to());
// The left part of the overlapping range doesn't overlap. // The left part of the overlapping range doesn't overlap.
// Truncate the whole entry to be just the left part. // Truncate the whole entry to be just the left part.
entry->set_to(left.to()); entry->set_to(left.to());
...@@ -6495,8 +6499,7 @@ class AddDispatchRange { ...@@ -6495,8 +6499,7 @@ class AddDispatchRange {
void AddDispatchRange::Call(uc32 from, DispatchTable::Entry entry) { void AddDispatchRange::Call(uc32 from, DispatchTable::Entry entry) {
CharacterRange range(from, entry.to()); constructor_->AddRange(CharacterRange::Range(from, entry.to()));
constructor_->AddRange(range);
} }
...@@ -6534,7 +6537,7 @@ void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) { ...@@ -6534,7 +6537,7 @@ void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) {
for (int i = 0; i < ranges->length(); i++) { for (int i = 0; i < ranges->length(); i++) {
CharacterRange range = ranges->at(i); CharacterRange range = ranges->at(i);
if (last < range.from()) if (last < range.from())
AddRange(CharacterRange(last, range.from() - 1)); AddRange(CharacterRange::Range(last, range.from() - 1));
if (range.to() >= last) { if (range.to() >= last) {
if (range.to() == String::kMaxUtf16CodeUnit) { if (range.to() == String::kMaxUtf16CodeUnit) {
return; return;
...@@ -6543,7 +6546,7 @@ void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) { ...@@ -6543,7 +6546,7 @@ void DispatchTableConstructor::AddInverse(ZoneList<CharacterRange>* ranges) {
} }
} }
} }
AddRange(CharacterRange(last, String::kMaxUtf16CodeUnit)); AddRange(CharacterRange::Range(last, String::kMaxUtf16CodeUnit));
} }
...@@ -6552,7 +6555,7 @@ void DispatchTableConstructor::VisitText(TextNode* that) { ...@@ -6552,7 +6555,7 @@ void DispatchTableConstructor::VisitText(TextNode* that) {
switch (elm.text_type()) { switch (elm.text_type()) {
case TextElement::ATOM: { case TextElement::ATOM: {
uc16 c = elm.atom()->data()[0]; uc16 c = elm.atom()->data()[0];
AddRange(CharacterRange(c, c)); AddRange(CharacterRange::Range(c, c));
break; break;
} }
case TextElement::CHAR_CLASS: { case TextElement::CHAR_CLASS: {
......
...@@ -78,10 +78,6 @@ class CharacterRange { ...@@ -78,10 +78,6 @@ class CharacterRange {
CharacterRange() : from_(0), to_(0) {} CharacterRange() : from_(0), to_(0) {}
// For compatibility with the CHECK_OK macro // For compatibility with the CHECK_OK macro
CharacterRange(void* null) { DCHECK_NULL(null); } // NOLINT CharacterRange(void* null) { DCHECK_NULL(null); } // NOLINT
CharacterRange(uc32 from, uc32 to) : from_(from), to_(to) {
DCHECK(0 <= from && to <= String::kMaxCodePoint);
DCHECK(static_cast<uint32_t>(from) <= static_cast<uint32_t>(to));
}
static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges, static void AddClassEscape(uc16 type, ZoneList<CharacterRange>* ranges,
Zone* zone); Zone* zone);
static Vector<const int> GetWordBounds(); static Vector<const int> GetWordBounds();
...@@ -89,6 +85,8 @@ class CharacterRange { ...@@ -89,6 +85,8 @@ class CharacterRange {
return CharacterRange(value, value); return CharacterRange(value, value);
} }
static inline CharacterRange Range(uc32 from, uc32 to) { static inline CharacterRange Range(uc32 from, uc32 to) {
DCHECK(0 <= from && to <= String::kMaxCodePoint);
DCHECK(static_cast<uint32_t>(from) <= static_cast<uint32_t>(to));
return CharacterRange(from, to); return CharacterRange(from, to);
} }
static inline CharacterRange Everything() { static inline CharacterRange Everything() {
...@@ -127,6 +125,8 @@ class CharacterRange { ...@@ -127,6 +125,8 @@ class CharacterRange {
static const int kPayloadMask = (1 << 24) - 1; static const int kPayloadMask = (1 << 24) - 1;
private: private:
CharacterRange(uc32 from, uc32 to) : from_(from), to_(to) {}
uc32 from_; uc32 from_;
uc32 to_; uc32 to_;
}; };
......
...@@ -686,7 +686,7 @@ TEST(DispatchTableConstruction) { ...@@ -686,7 +686,7 @@ TEST(DispatchTableConstruction) {
for (int i = 0; i < kRangeCount; i++) { for (int i = 0; i < kRangeCount; i++) {
uc16* range = ranges[i]; uc16* range = ranges[i];
for (int j = 0; j < 2 * kRangeSize; j += 2) for (int j = 0; j < 2 * kRangeSize; j += 2)
table.AddRange(CharacterRange(range[j], range[j + 1]), i, &zone); table.AddRange(CharacterRange::Range(range[j], range[j + 1]), i, &zone);
} }
// Check that the table looks as we would expect // Check that the table looks as we would expect
for (int p = 0; p < kLimit; p++) { for (int p = 0; p < kLimit; p++) {
...@@ -1498,7 +1498,7 @@ TEST(AddInverseToTable) { ...@@ -1498,7 +1498,7 @@ TEST(AddInverseToTable) {
int from = PseudoRandom(t + 87, i + 25) % kLimit; int from = PseudoRandom(t + 87, i + 25) % kLimit;
int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20));
if (to > kLimit) to = kLimit; if (to > kLimit) to = kLimit;
ranges->Add(CharacterRange(from, to), &zone); ranges->Add(CharacterRange::Range(from, to), &zone);
} }
DispatchTable table(&zone); DispatchTable table(&zone);
DispatchTableConstructor cons(&table, false, &zone); DispatchTableConstructor cons(&table, false, &zone);
...@@ -1515,7 +1515,7 @@ TEST(AddInverseToTable) { ...@@ -1515,7 +1515,7 @@ TEST(AddInverseToTable) {
Zone zone; Zone zone;
ZoneList<CharacterRange>* ranges = ZoneList<CharacterRange>* ranges =
new(&zone) ZoneList<CharacterRange>(1, &zone); new(&zone) ZoneList<CharacterRange>(1, &zone);
ranges->Add(CharacterRange(0xFFF0, 0xFFFE), &zone); ranges->Add(CharacterRange::Range(0xFFF0, 0xFFFE), &zone);
DispatchTable table(&zone); DispatchTable table(&zone);
DispatchTableConstructor cons(&table, false, &zone); DispatchTableConstructor cons(&table, false, &zone);
cons.set_choice_index(0); cons.set_choice_index(0);
...@@ -1655,27 +1655,29 @@ TEST(CharacterRangeCaseIndependence) { ...@@ -1655,27 +1655,29 @@ TEST(CharacterRangeCaseIndependence) {
CharacterRange::Singleton('A')); CharacterRange::Singleton('A'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('z'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('z'),
CharacterRange::Singleton('Z')); CharacterRange::Singleton('Z'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'z'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('a', 'z'),
CharacterRange('A', 'Z')); CharacterRange::Range('A', 'Z'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange('c', 'f'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('c', 'f'),
CharacterRange('C', 'F')); CharacterRange::Range('C', 'F'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'b'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('a', 'b'),
CharacterRange('A', 'B')); CharacterRange::Range('A', 'B'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange('y', 'z'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('y', 'z'),
CharacterRange('Y', 'Z')); CharacterRange::Range('Y', 'Z'));
TestSimpleRangeCaseIndependence(isolate, CharacterRange('a' - 1, 'z' + 1), TestSimpleRangeCaseIndependence(isolate,
CharacterRange('A', 'Z')); CharacterRange::Range('a' - 1, 'z' + 1),
TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'Z'), CharacterRange::Range('A', 'Z'));
CharacterRange('a', 'z')); TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('A', 'Z'),
TestSimpleRangeCaseIndependence(isolate, CharacterRange('C', 'F'), CharacterRange::Range('a', 'z'));
CharacterRange('c', 'f')); TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('C', 'F'),
TestSimpleRangeCaseIndependence(isolate, CharacterRange('A' - 1, 'Z' + 1), CharacterRange::Range('c', 'f'));
CharacterRange('a', 'z')); TestSimpleRangeCaseIndependence(isolate,
CharacterRange::Range('A' - 1, 'Z' + 1),
CharacterRange::Range('a', 'z'));
// Here we need to add [l-z] to complete the case independence of // Here we need to add [l-z] to complete the case independence of
// [A-Za-z] but we expect [a-z] to be added since we always add a // [A-Za-z] but we expect [a-z] to be added since we always add a
// whole block at a time. // whole block at a time.
TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'k'), TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('A', 'k'),
CharacterRange('a', 'z')); CharacterRange::Range('a', 'z'));
} }
...@@ -1741,9 +1743,9 @@ TEST(CanonicalizeCharacterSets) { ...@@ -1741,9 +1743,9 @@ TEST(CanonicalizeCharacterSets) {
new(&zone) ZoneList<CharacterRange>(4, &zone); new(&zone) ZoneList<CharacterRange>(4, &zone);
CharacterSet set(list); CharacterSet set(list);
list->Add(CharacterRange(10, 20), &zone); list->Add(CharacterRange::Range(10, 20), &zone);
list->Add(CharacterRange(30, 40), &zone); list->Add(CharacterRange::Range(30, 40), &zone);
list->Add(CharacterRange(50, 60), &zone); list->Add(CharacterRange::Range(50, 60), &zone);
set.Canonicalize(); set.Canonicalize();
CHECK_EQ(3, list->length()); CHECK_EQ(3, list->length());
CHECK_EQ(10, list->at(0).from()); CHECK_EQ(10, list->at(0).from());
...@@ -1754,9 +1756,9 @@ TEST(CanonicalizeCharacterSets) { ...@@ -1754,9 +1756,9 @@ TEST(CanonicalizeCharacterSets) {
CHECK_EQ(60, list->at(2).to()); CHECK_EQ(60, list->at(2).to());
list->Rewind(0); list->Rewind(0);
list->Add(CharacterRange(10, 20), &zone); list->Add(CharacterRange::Range(10, 20), &zone);
list->Add(CharacterRange(50, 60), &zone); list->Add(CharacterRange::Range(50, 60), &zone);
list->Add(CharacterRange(30, 40), &zone); list->Add(CharacterRange::Range(30, 40), &zone);
set.Canonicalize(); set.Canonicalize();
CHECK_EQ(3, list->length()); CHECK_EQ(3, list->length());
CHECK_EQ(10, list->at(0).from()); CHECK_EQ(10, list->at(0).from());
...@@ -1767,11 +1769,11 @@ TEST(CanonicalizeCharacterSets) { ...@@ -1767,11 +1769,11 @@ TEST(CanonicalizeCharacterSets) {
CHECK_EQ(60, list->at(2).to()); CHECK_EQ(60, list->at(2).to());
list->Rewind(0); list->Rewind(0);
list->Add(CharacterRange(30, 40), &zone); list->Add(CharacterRange::Range(30, 40), &zone);
list->Add(CharacterRange(10, 20), &zone); list->Add(CharacterRange::Range(10, 20), &zone);
list->Add(CharacterRange(25, 25), &zone); list->Add(CharacterRange::Range(25, 25), &zone);
list->Add(CharacterRange(100, 100), &zone); list->Add(CharacterRange::Range(100, 100), &zone);
list->Add(CharacterRange(1, 1), &zone); list->Add(CharacterRange::Range(1, 1), &zone);
set.Canonicalize(); set.Canonicalize();
CHECK_EQ(5, list->length()); CHECK_EQ(5, list->length());
CHECK_EQ(1, list->at(0).from()); CHECK_EQ(1, list->at(0).from());
...@@ -1786,9 +1788,9 @@ TEST(CanonicalizeCharacterSets) { ...@@ -1786,9 +1788,9 @@ TEST(CanonicalizeCharacterSets) {
CHECK_EQ(100, list->at(4).to()); CHECK_EQ(100, list->at(4).to());
list->Rewind(0); list->Rewind(0);
list->Add(CharacterRange(10, 19), &zone); list->Add(CharacterRange::Range(10, 19), &zone);
list->Add(CharacterRange(21, 30), &zone); list->Add(CharacterRange::Range(21, 30), &zone);
list->Add(CharacterRange(20, 20), &zone); list->Add(CharacterRange::Range(20, 20), &zone);
set.Canonicalize(); set.Canonicalize();
CHECK_EQ(1, list->length()); CHECK_EQ(1, list->length());
CHECK_EQ(10, list->at(0).from()); CHECK_EQ(10, list->at(0).from());
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc --stack-size=120
var __v_11 = {};
function __f_2(depth) {
try {
__f_5(depth, __v_11);
return true;
} catch (e) {
gc();
}
}
function __f_5(n, __v_4) {
if (--n == 0) {
__f_1(__v_4);
return;
}
__f_5(n, __v_4);
}
function __f_1(__v_4) {
var __v_5 = new RegExp(__v_4);
}
function __f_4() {
var __v_1 = 100;
var __v_8 = 100000;
while (__v_1 < __v_8 - 1) {
var __v_3 = Math.floor((__v_1 + __v_8) / 2);
if (__f_2(__v_3)) {
__v_1 = __v_3;
} else {
__v_8 = __v_3;
}
}
}
__f_4();
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