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

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

Issue 949343002: Fix array-out-of-bounds in TypedDataView::ElementSizeInBytes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 6931 matching lines...) Expand 10 before | Expand all | Expand 10 after
6942 return 0; 6942 return 0;
6943 } 6943 }
6944 6944
6945 static intptr_t InstanceSize(intptr_t lengthInBytes) { 6945 static intptr_t InstanceSize(intptr_t lengthInBytes) {
6946 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); 6946 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax);
6947 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); 6947 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes);
6948 } 6948 }
6949 6949
6950 static intptr_t ElementSizeInBytes(intptr_t class_id) { 6950 static intptr_t ElementSizeInBytes(intptr_t class_id) {
6951 ASSERT(RawObject::IsTypedDataClassId(class_id)); 6951 ASSERT(RawObject::IsTypedDataClassId(class_id));
6952 return element_size[ElementType(class_id)]; 6952 return element_size(ElementType(class_id));
6953 } 6953 }
6954 6954
6955 static TypedDataElementType ElementType(intptr_t class_id) { 6955 static TypedDataElementType ElementType(intptr_t class_id) {
6956 ASSERT(RawObject::IsTypedDataClassId(class_id)); 6956 ASSERT(RawObject::IsTypedDataClassId(class_id));
6957 return static_cast<TypedDataElementType>( 6957 return static_cast<TypedDataElementType>(
6958 class_id - kTypedDataInt8ArrayCid); 6958 class_id - kTypedDataInt8ArrayCid);
6959 } 6959 }
6960 6960
6961 static intptr_t MaxElements(intptr_t class_id) { 6961 static intptr_t MaxElements(intptr_t class_id) {
6962 ASSERT(RawObject::IsTypedDataClassId(class_id)); 6962 ASSERT(RawObject::IsTypedDataClassId(class_id));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7023 } 7023 }
7024 7024
7025 static RawTypedData* EmptyUint32Array(Isolate* isolate); 7025 static RawTypedData* EmptyUint32Array(Isolate* isolate);
7026 7026
7027 protected: 7027 protected:
7028 void SetLength(intptr_t value) const { 7028 void SetLength(intptr_t value) const {
7029 StoreSmi(&raw_ptr()->length_, Smi::New(value)); 7029 StoreSmi(&raw_ptr()->length_, Smi::New(value));
7030 } 7030 }
7031 7031
7032 private: 7032 private:
7033 static const intptr_t element_size[]; 7033 static intptr_t element_size(intptr_t index) {
7034 ASSERT(0 <= index && index < kNumElementSizes);
7035 intptr_t size = element_size_table[index]
7036 ASSERT(size != 0);
7037 return size;
7038 }
7039 static const intptr_t kNumElementSizes = 14;
Ivan Posva 2015/02/25 23:52:44 Where does 14 come from?
koda 2015/02/25 23:57:59 That's the number of elements in the array; see ob
Ivan Posva 2015/02/26 00:15:44 Isn't it "(kTypedDataFloat64x2ArrayCid - kTypedDat
koda 2015/02/27 18:21:57 Done. Sure. Until we add another type :) In any c
7040 static const intptr_t element_size_table[kNumElementSizes];
7034 7041
7035 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); 7042 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance);
7036 friend class Class; 7043 friend class Class;
7037 friend class ExternalTypedData; 7044 friend class ExternalTypedData;
7038 friend class TypedDataView; 7045 friend class TypedDataView;
7039 }; 7046 };
7040 7047
7041 7048
7042 class ExternalTypedData : public Instance { 7049 class ExternalTypedData : public Instance {
7043 public: 7050 public:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
7100 static intptr_t data_offset() { 7107 static intptr_t data_offset() {
7101 return OFFSET_OF(RawExternalTypedData, data_); 7108 return OFFSET_OF(RawExternalTypedData, data_);
7102 } 7109 }
7103 7110
7104 static intptr_t InstanceSize() { 7111 static intptr_t InstanceSize() {
7105 return RoundedAllocationSize(sizeof(RawExternalTypedData)); 7112 return RoundedAllocationSize(sizeof(RawExternalTypedData));
7106 } 7113 }
7107 7114
7108 static intptr_t ElementSizeInBytes(intptr_t class_id) { 7115 static intptr_t ElementSizeInBytes(intptr_t class_id) {
7109 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); 7116 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
7110 return TypedData::element_size[ElementType(class_id)]; 7117 return TypedData::element_size(ElementType(class_id));
7111 } 7118 }
7112 7119
7113 static TypedDataElementType ElementType(intptr_t class_id) { 7120 static TypedDataElementType ElementType(intptr_t class_id) {
7114 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); 7121 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
7115 return static_cast<TypedDataElementType>( 7122 return static_cast<TypedDataElementType>(
7116 class_id - kExternalTypedDataInt8ArrayCid); 7123 class_id - kExternalTypedDataInt8ArrayCid);
7117 } 7124 }
7118 7125
7119 static intptr_t MaxElements(intptr_t class_id) { 7126 static intptr_t MaxElements(intptr_t class_id) {
7120 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); 7127 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
7193 return kWordSize * kOffsetInBytesOffset; 7200 return kWordSize * kOffsetInBytesOffset;
7194 } 7201 }
7195 7202
7196 static intptr_t length_offset() { 7203 static intptr_t length_offset() {
7197 return kWordSize * kLengthOffset; 7204 return kWordSize * kLengthOffset;
7198 } 7205 }
7199 7206
7200 static intptr_t ElementSizeInBytes(intptr_t class_id) { 7207 static intptr_t ElementSizeInBytes(intptr_t class_id) {
7201 ASSERT(RawObject::IsTypedDataViewClassId(class_id)); 7208 ASSERT(RawObject::IsTypedDataViewClassId(class_id));
7202 return (class_id == kByteDataViewCid) ? 7209 return (class_id == kByteDataViewCid) ?
7203 TypedData::element_size[kTypedDataInt8ArrayCid] : 7210 1 : TypedData::element_size(class_id - kTypedDataInt8ArrayViewCid);
7204 TypedData::element_size[class_id - kTypedDataInt8ArrayViewCid];
7205 } 7211 }
7206 7212
7207 private: 7213 private:
7208 enum { 7214 enum {
7209 kDataOffset = 1, 7215 kDataOffset = 1,
7210 kOffsetInBytesOffset = 2, 7216 kOffsetInBytesOffset = 2,
7211 kLengthOffset = 3, 7217 kLengthOffset = 3,
7212 }; 7218 };
7213 }; 7219 };
7214 7220
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
7806 7812
7807 7813
7808 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7814 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7809 intptr_t index) { 7815 intptr_t index) {
7810 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7816 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7811 } 7817 }
7812 7818
7813 } // namespace dart 7819 } // namespace dart
7814 7820
7815 #endif // VM_OBJECT_H_ 7821 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698