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

Side by Side Diff: lib/string.cc

Issue 10782016: Enforce length/size limits for variable size heap object in order to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/exceptions.h" 7 #include "vm/exceptions.h"
8 #include "vm/native_entry.h" 8 #include "vm/native_entry.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { 13 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
14 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); 14 GET_NATIVE_ARGUMENT(Array, a, arguments->At(0));
15 // TODO(srdjan): Check that parameterized type is an int. 15 // TODO(srdjan): Check that parameterized type is an int.
16 Zone* zone = Isolate::Current()->current_zone(); 16 Zone* zone = Isolate::Current()->current_zone();
17 intptr_t len = a.Length(); 17 intptr_t len = a.Length();
18 18
cshapiro 2012/07/17 22:54:30 The native argument is always a built-in Array. W
turnidge 2012/07/18 18:17:04 Done.
19 // Currently the dart code copies all of the codepoints to another
20 // object array, so we are assured that the lengths will probably be
21 // sane since they are limited by the heap.
22 //
23 // Nonetheless, make sure that we enforce maximum element counts for
24 // strings, as the dart code may change.
25 if (len < 0 || len > FourByteString::kMaxElements) {
26 const String& error = String::Handle(String::NewFormatted(
27 "codePoints.length (%ld) must be in the range [0..%ld]",
28 len, Array::kMaxElements));
29 GrowableArray<const Object*> args;
30 args.Add(&error);
31 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
32 }
33
19 // Unbox the array and determine the maximum element width. 34 // Unbox the array and determine the maximum element width.
20 bool is_one_byte_string = true; 35 bool is_one_byte_string = true;
21 bool is_two_byte_string = true; 36 bool is_two_byte_string = true;
22 uint32_t* temp = reinterpret_cast<uint32_t*>( 37 uint32_t* temp = reinterpret_cast<uint32_t*>(
23 zone->Allocate(len * sizeof(uint32_t))); // NOLINT 38 zone->Allocate(len * sizeof(uint32_t))); // NOLINT
24 Smi& element = Smi::Handle(); 39 Smi& element = Smi::Handle();
25 for (intptr_t i = 0; i < len; i++) { 40 for (intptr_t i = 0; i < len; i++) {
26 const Object& index_object = Object::Handle(a.At(i)); 41 const Object& index_object = Object::Handle(a.At(i));
27 if (!index_object.IsSmi()) { 42 if (!index_object.IsSmi()) {
28 GrowableArray<const Object*> args; 43 GrowableArray<const Object*> args;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 GrowableArray<const Object*> args; 163 GrowableArray<const Object*> args;
149 args.Add(&elem); 164 args.Add(&elem);
150 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); 165 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args);
151 } 166 }
152 } 167 }
153 const String& result = String::Handle(String::ConcatAll(strings)); 168 const String& result = String::Handle(String::ConcatAll(strings));
154 arguments->SetReturn(result); 169 arguments->SetReturn(result);
155 } 170 }
156 171
157 } // namespace dart 172 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698