Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1651)

Unified Diff: src/runtime.cc

Issue 210143002: Revert "No longer OOM on invalid string length." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | src/uri.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 706f1ff09fa11a0c45e62ba455572b12bacc1056..89dbb0b2730a4c7ea1e300249f718a92cafc85b1 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -3344,7 +3344,8 @@ class ReplacementStringBuilder {
array_builder_(heap->isolate(), estimated_part_count),
subject_(subject),
character_count_(0),
- is_ascii_(subject->IsOneByteRepresentation()) {
+ is_ascii_(subject->IsOneByteRepresentation()),
+ overflowed_(false) {
// Require a non-zero initial size. Ensures that doubling the size to
// extend the array will work.
ASSERT(estimated_part_count > 0);
@@ -3392,6 +3393,11 @@ class ReplacementStringBuilder {
Handle<String> ToString() {
+ if (overflowed_) {
+ heap_->isolate()->ThrowInvalidStringLength();
+ return Handle<String>();
+ }
+
if (array_builder_.length() == 0) {
return heap_->isolate()->factory()->empty_string();
}
@@ -3399,7 +3405,6 @@ class ReplacementStringBuilder {
Handle<String> joined_string;
if (is_ascii_) {
Handle<SeqOneByteString> seq = NewRawOneByteString(character_count_);
- RETURN_IF_EMPTY_HANDLE_VALUE(heap_->isolate(), seq, Handle<String>());
DisallowHeapAllocation no_gc;
uint8_t* char_buffer = seq->GetChars();
StringBuilderConcatHelper(*subject_,
@@ -3410,7 +3415,6 @@ class ReplacementStringBuilder {
} else {
// Non-ASCII.
Handle<SeqTwoByteString> seq = NewRawTwoByteString(character_count_);
- RETURN_IF_EMPTY_HANDLE_VALUE(heap_->isolate(), seq, Handle<String>());
DisallowHeapAllocation no_gc;
uc16* char_buffer = seq->GetChars();
StringBuilderConcatHelper(*subject_,
@@ -3425,11 +3429,9 @@ class ReplacementStringBuilder {
void IncrementCharacterCount(int by) {
if (character_count_ > String::kMaxLength - by) {
- STATIC_ASSERT(String::kMaxLength < kMaxInt);
- character_count_ = kMaxInt;
- } else {
- character_count_ += by;
+ overflowed_ = true;
}
+ character_count_ += by;
}
private:
@@ -3454,6 +3456,7 @@ class ReplacementStringBuilder {
Handle<String> subject_;
int character_count_;
bool is_ascii_;
+ bool overflowed_;
};
@@ -3910,13 +3913,10 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString(
static_cast<int64_t>(pattern_len)) *
static_cast<int64_t>(matches) +
static_cast<int64_t>(subject_len);
- int result_len;
- if (result_len_64 > static_cast<int64_t>(String::kMaxLength)) {
- STATIC_ASSERT(String::kMaxLength < kMaxInt);
- result_len = kMaxInt; // Provoke exception.
- } else {
- result_len = static_cast<int>(result_len_64);
+ if (result_len_64 > INT_MAX) {
+ v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true);
}
+ int result_len = static_cast<int>(result_len_64);
int subject_pos = 0;
int result_pos = 0;
@@ -3929,7 +3929,6 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString(
result = Handle<ResultSeqString>::cast(
isolate->factory()->NewRawTwoByteString(result_len));
}
- RETURN_IF_EMPTY_HANDLE(isolate, result);
for (int i = 0; i < matches; i++) {
// Copy non-matched subject content.
@@ -4109,7 +4108,6 @@ MUST_USE_RESULT static MaybeObject* StringReplaceGlobalRegExpWithEmptyString(
answer = Handle<ResultSeqString>::cast(
isolate->factory()->NewRawTwoByteString(new_length));
}
- ASSERT(!answer.is_null());
int prev = 0;
int position = 0;
@@ -6567,7 +6565,7 @@ MUST_USE_RESULT static MaybeObject* ConvertCase(
if (s->IsOneByteRepresentationUnderneath()) {
Handle<SeqOneByteString> result =
isolate->factory()->NewRawOneByteString(length);
- ASSERT(!result.is_null()); // Same length as input.
+
DisallowHeapAllocation no_gc;
String::FlatContent flat_content = s->GetFlatContent();
ASSERT(flat_content.IsFlat());
@@ -6587,8 +6585,6 @@ MUST_USE_RESULT static MaybeObject* ConvertCase(
} else {
result = isolate->factory()->NewRawTwoByteString(length);
}
- ASSERT(!result.is_null()); // Same length as input.
-
MaybeObject* maybe = ConvertCaseHelper(isolate, *s, *result, length, mapping);
Object* answer;
if (!maybe->ToObject(&answer)) return maybe;
@@ -6602,7 +6598,6 @@ MUST_USE_RESULT static MaybeObject* ConvertCase(
if (length < 0) length = -length;
result = isolate->factory()->NewRawTwoByteString(length);
}
- RETURN_IF_EMPTY_HANDLE(isolate, result);
return ConvertCaseHelper(isolate, *s, *result, length, mapping);
}
@@ -7247,16 +7242,13 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderJoin) {
String* element = String::cast(element_obj);
int increment = element->length();
if (increment > String::kMaxLength - length) {
- STATIC_ASSERT(String::kMaxLength < kMaxInt);
- length = kMaxInt; // Provoke exception;
- break;
+ return isolate->ThrowInvalidStringLength();
}
length += increment;
}
Handle<SeqTwoByteString> answer =
isolate->factory()->NewRawTwoByteString(length);
- RETURN_IF_EMPTY_HANDLE(isolate, answer);
DisallowHeapAllocation no_gc;
@@ -9501,9 +9493,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ThrowMessage) {
CONVERT_SMI_ARG_CHECKED(message_id, 0);
const char* message = GetBailoutReason(
static_cast<BailoutReason>(message_id));
- Handle<String> message_handle =
+ Handle<Name> message_handle =
isolate->factory()->NewStringFromAscii(CStrVector(message));
- RETURN_IF_EMPTY_HANDLE(isolate, message_handle);
return isolate->Throw(*message_handle);
}
« no previous file with comments | « src/parser.cc ('k') | src/uri.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698