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

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

Issue 23691013: Add checks catching potential integer overflows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | no next file » | 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 8104 matching lines...) Expand 10 before | Expand all | Expand 10 after
8115 BitmapBuilder* bmap, 8115 BitmapBuilder* bmap,
8116 intptr_t register_bit_count) { 8116 intptr_t register_bit_count) {
8117 ASSERT(Object::stackmap_class() != Class::null()); 8117 ASSERT(Object::stackmap_class() != Class::null());
8118 ASSERT(bmap != NULL); 8118 ASSERT(bmap != NULL);
8119 Stackmap& result = Stackmap::Handle(); 8119 Stackmap& result = Stackmap::Handle();
8120 // Guard against integer overflow of the instance size computation. 8120 // Guard against integer overflow of the instance size computation.
8121 intptr_t length = bmap->Length(); 8121 intptr_t length = bmap->Length();
8122 intptr_t payload_size = 8122 intptr_t payload_size =
8123 Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte; 8123 Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte;
8124 if ((payload_size < 0) || 8124 if ((payload_size < 0) ||
8125 (payload_size > 8125 (payload_size > kMaxLengthInBytes)) {
8126 (kSmiMax - static_cast<intptr_t>(sizeof(RawStackmap))))) {
8127 // This should be caught before we reach here. 8126 // This should be caught before we reach here.
8128 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n", 8127 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n",
8129 length); 8128 length);
8130 } 8129 }
8131 { 8130 {
8132 // Stackmap data objects are associated with a code object, allocate them 8131 // Stackmap data objects are associated with a code object, allocate them
8133 // in old generation. 8132 // in old generation.
8134 RawObject* raw = Object::Allocate(Stackmap::kClassId, 8133 RawObject* raw = Object::Allocate(Stackmap::kClassId,
8135 Stackmap::InstanceSize(length), 8134 Stackmap::InstanceSize(length),
8136 Heap::kOld); 8135 Heap::kOld);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
8540 8539
8541 8540
8542 void DeoptInfo::PrintToJSONStream(JSONStream* stream, bool ref) const { 8541 void DeoptInfo::PrintToJSONStream(JSONStream* stream, bool ref) const {
8543 stream->OpenObject(); 8542 stream->OpenObject();
8544 stream->CloseObject(); 8543 stream->CloseObject();
8545 } 8544 }
8546 8545
8547 8546
8548 RawDeoptInfo* DeoptInfo::New(intptr_t num_commands) { 8547 RawDeoptInfo* DeoptInfo::New(intptr_t num_commands) {
8549 ASSERT(Object::deopt_info_class() != Class::null()); 8548 ASSERT(Object::deopt_info_class() != Class::null());
8549 if ((num_commands < 0) || (num_commands > kMaxElements)) {
8550 FATAL1("Fatal error in DeoptInfo::New(): invalid num_commands %" Pd "\n",
8551 num_commands);
8552 }
8550 DeoptInfo& result = DeoptInfo::Handle(); 8553 DeoptInfo& result = DeoptInfo::Handle();
8551 { 8554 {
8552 uword size = DeoptInfo::InstanceSize(num_commands); 8555 uword size = DeoptInfo::InstanceSize(num_commands);
8553 RawObject* raw = Object::Allocate(DeoptInfo::kClassId, 8556 RawObject* raw = Object::Allocate(DeoptInfo::kClassId,
8554 size, 8557 size,
8555 Heap::kOld); 8558 Heap::kOld);
8556 NoGCScope no_gc; 8559 NoGCScope no_gc;
8557 result ^= raw; 8560 result ^= raw;
8558 result.SetLength(num_commands); 8561 result.SetLength(num_commands);
8559 } 8562 }
(...skipping 5794 matching lines...) Expand 10 before | Expand all | Expand 10 after
14354 8, // kTypedDataUint64ArrayCid. 14357 8, // kTypedDataUint64ArrayCid.
14355 4, // kTypedDataFloat32ArrayCid. 14358 4, // kTypedDataFloat32ArrayCid.
14356 8, // kTypedDataFloat64ArrayCid. 14359 8, // kTypedDataFloat64ArrayCid.
14357 16, // kTypedDataFloat32x4ArrayCid. 14360 16, // kTypedDataFloat32x4ArrayCid.
14358 }; 14361 };
14359 14362
14360 14363
14361 RawTypedData* TypedData::New(intptr_t class_id, 14364 RawTypedData* TypedData::New(intptr_t class_id,
14362 intptr_t len, 14365 intptr_t len,
14363 Heap::Space space) { 14366 Heap::Space space) {
14364 // TODO(asiva): Add a check for maximum elements. 14367 if (len < 0 || len > TypedData::MaxElements(class_id)) {
14368 FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len);
14369 }
14365 TypedData& result = TypedData::Handle(); 14370 TypedData& result = TypedData::Handle();
14366 { 14371 {
14367 // The len field has already been checked by the caller, we only assert
14368 // here that it is within a valid range.
14369 ASSERT((len >= 0) &&
14370 (len < (kSmiMax / TypedData::ElementSizeInBytes(class_id))));
14371 intptr_t lengthInBytes = len * ElementSizeInBytes(class_id); 14372 intptr_t lengthInBytes = len * ElementSizeInBytes(class_id);
14372 RawObject* raw = Object::Allocate(class_id, 14373 RawObject* raw = Object::Allocate(class_id,
14373 TypedData::InstanceSize(lengthInBytes), 14374 TypedData::InstanceSize(lengthInBytes),
14374 space); 14375 space);
14375 NoGCScope no_gc; 14376 NoGCScope no_gc;
14376 result ^= raw; 14377 result ^= raw;
14377 result.SetLength(len); 14378 result.SetLength(len);
14378 if (len > 0) { 14379 if (len > 0) {
14379 memset(result.DataAddr(0), 0, lengthInBytes); 14380 memset(result.DataAddr(0), 0, lengthInBytes);
14380 } 14381 }
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
14888 } 14889 }
14889 14890
14890 14891
14891 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14892 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14892 stream->OpenObject(); 14893 stream->OpenObject();
14893 stream->CloseObject(); 14894 stream->CloseObject();
14894 } 14895 }
14895 14896
14896 14897
14897 } // namespace dart 14898 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698