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

Side by Side Diff: runtime/vm/object.cc

Issue 16783003: Fix issue 11214 avoid length overflow in String::ConcatAll (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/string_overflow.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 11695 matching lines...) Expand 10 before | Expand all | Expand 10 after
11706 11706
11707 RawString* String::ConcatAll(const Array& strings, 11707 RawString* String::ConcatAll(const Array& strings,
11708 Heap::Space space) { 11708 Heap::Space space) {
11709 ASSERT(!strings.IsNull()); 11709 ASSERT(!strings.IsNull());
11710 intptr_t result_len = 0; 11710 intptr_t result_len = 0;
11711 intptr_t strings_len = strings.Length(); 11711 intptr_t strings_len = strings.Length();
11712 String& str = String::Handle(); 11712 String& str = String::Handle();
11713 intptr_t char_size = kOneByteChar; 11713 intptr_t char_size = kOneByteChar;
11714 for (intptr_t i = 0; i < strings_len; i++) { 11714 for (intptr_t i = 0; i < strings_len; i++) {
11715 str ^= strings.At(i); 11715 str ^= strings.At(i);
11716 result_len += str.Length(); 11716 intptr_t str_len = str.Length();
11717 if ((kMaxElements - result_len) < str_len) {
11718 Isolate* isolate = Isolate::Current();
11719 const Instance& exception =
11720 Instance::Handle(isolate->object_store()->out_of_memory());
11721 Exceptions::Throw(exception);
11722 UNREACHABLE();
11723 }
11724 result_len += str_len;
11717 char_size = Utils::Maximum(char_size, str.CharSize()); 11725 char_size = Utils::Maximum(char_size, str.CharSize());
11718 } 11726 }
11719 if (char_size == kOneByteChar) { 11727 if (char_size == kOneByteChar) {
11720 return OneByteString::ConcatAll(strings, result_len, space); 11728 return OneByteString::ConcatAll(strings, result_len, space);
11721 } 11729 }
11722 ASSERT(char_size == kTwoByteChar); 11730 ASSERT(char_size == kTwoByteChar);
11723 return TwoByteString::ConcatAll(strings, result_len, space); 11731 return TwoByteString::ConcatAll(strings, result_len, space);
11724 } 11732 }
11725 11733
11726 11734
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
12180 intptr_t len, 12188 intptr_t len,
12181 Heap::Space space) { 12189 Heap::Space space) {
12182 const String& result = String::Handle(OneByteString::New(len, space)); 12190 const String& result = String::Handle(OneByteString::New(len, space));
12183 String& str = String::Handle(); 12191 String& str = String::Handle();
12184 intptr_t strings_len = strings.Length(); 12192 intptr_t strings_len = strings.Length();
12185 intptr_t pos = 0; 12193 intptr_t pos = 0;
12186 for (intptr_t i = 0; i < strings_len; i++) { 12194 for (intptr_t i = 0; i < strings_len; i++) {
12187 str ^= strings.At(i); 12195 str ^= strings.At(i);
12188 intptr_t str_len = str.Length(); 12196 intptr_t str_len = str.Length();
12189 String::Copy(result, pos, str, 0, str_len); 12197 String::Copy(result, pos, str, 0, str_len);
12198 ASSERT((kMaxElements - pos) >= str_len);
12190 pos += str_len; 12199 pos += str_len;
12191 } 12200 }
12192 return OneByteString::raw(result); 12201 return OneByteString::raw(result);
12193 } 12202 }
12194 12203
12195 12204
12196 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), 12205 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
12197 const String& str, 12206 const String& str,
12198 Heap::Space space) { 12207 Heap::Space space) {
12199 ASSERT(!str.IsNull()); 12208 ASSERT(!str.IsNull());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
12343 intptr_t len, 12352 intptr_t len,
12344 Heap::Space space) { 12353 Heap::Space space) {
12345 const String& result = String::Handle(TwoByteString::New(len, space)); 12354 const String& result = String::Handle(TwoByteString::New(len, space));
12346 String& str = String::Handle(); 12355 String& str = String::Handle();
12347 intptr_t strings_len = strings.Length(); 12356 intptr_t strings_len = strings.Length();
12348 intptr_t pos = 0; 12357 intptr_t pos = 0;
12349 for (intptr_t i = 0; i < strings_len; i++) { 12358 for (intptr_t i = 0; i < strings_len; i++) {
12350 str ^= strings.At(i); 12359 str ^= strings.At(i);
12351 intptr_t str_len = str.Length(); 12360 intptr_t str_len = str.Length();
12352 String::Copy(result, pos, str, 0, str_len); 12361 String::Copy(result, pos, str, 0, str_len);
12362 ASSERT((kMaxElements - pos) >= str_len);
12353 pos += str_len; 12363 pos += str_len;
12354 } 12364 }
12355 return TwoByteString::raw(result); 12365 return TwoByteString::raw(result);
12356 } 12366 }
12357 12367
12358 12368
12359 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), 12369 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch),
12360 const String& str, 12370 const String& str,
12361 Heap::Space space) { 12371 Heap::Space space) {
12362 ASSERT(!str.IsNull()); 12372 ASSERT(!str.IsNull());
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
13402 space); 13412 space);
13403 return reinterpret_cast<RawWeakProperty*>(raw); 13413 return reinterpret_cast<RawWeakProperty*>(raw);
13404 } 13414 }
13405 13415
13406 13416
13407 const char* WeakProperty::ToCString() const { 13417 const char* WeakProperty::ToCString() const {
13408 return "_WeakProperty"; 13418 return "_WeakProperty";
13409 } 13419 }
13410 13420
13411 } // namespace dart 13421 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/string_overflow.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698