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

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

Issue 23479010: Add length checks to ApiMessageWriter. (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 | « runtime/vm/dart_api_message.cc ('k') | 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 ApiMessageWriter writer(&buffer, &malloc_allocator); 124 ApiMessageWriter writer(&buffer, &malloc_allocator);
125 writer.WriteCMessage(root); 125 writer.WriteCMessage(root);
126 126
127 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator); 127 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator);
128 Dart_CObject* new_root = api_reader.ReadMessage(); 128 Dart_CObject* new_root = api_reader.ReadMessage();
129 129
130 // Check that the two messages are the same. 130 // Check that the two messages are the same.
131 CompareDartCObjects(root, new_root); 131 CompareDartCObjects(root, new_root);
132 } 132 }
133 133
134
135 static void ExpectEncodeFail(Dart_CObject* root) {
136 uint8_t* buffer = NULL;
137 ApiMessageWriter writer(&buffer, &malloc_allocator);
138 const bool result = writer.WriteCMessage(root);
139 EXPECT_EQ(false, result);
140 }
141
142
134 TEST_CASE(SerializeNull) { 143 TEST_CASE(SerializeNull) {
135 StackZone zone(Isolate::Current()); 144 StackZone zone(Isolate::Current());
136 145
137 // Write snapshot with object content. 146 // Write snapshot with object content.
138 uint8_t* buffer; 147 uint8_t* buffer;
139 MessageWriter writer(&buffer, &zone_allocator); 148 MessageWriter writer(&buffer, &zone_allocator);
140 const Object& null_object = Object::Handle(); 149 const Object& null_object = Object::Handle();
141 writer.WriteMessage(null_object); 150 writer.WriteMessage(null_object);
142 intptr_t buffer_len = writer.BytesWritten(); 151 intptr_t buffer_len = writer.BytesWritten();
143 152
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_EQ(kArrayLength, root->value.as_array.length); 582 EXPECT_EQ(kArrayLength, root->value.as_array.length);
574 for (int i = 0; i < kArrayLength; i++) { 583 for (int i = 0; i < kArrayLength; i++) {
575 Dart_CObject* element = root->value.as_array.values[i]; 584 Dart_CObject* element = root->value.as_array.values[i];
576 EXPECT_EQ(Dart_CObject_kInt32, element->type); 585 EXPECT_EQ(Dart_CObject_kInt32, element->type);
577 EXPECT_EQ(i, element->value.as_int32); 586 EXPECT_EQ(i, element->value.as_int32);
578 } 587 }
579 CheckEncodeDecodeMessage(root); 588 CheckEncodeDecodeMessage(root);
580 } 589 }
581 590
582 591
592 TEST_CASE(FailSerializeLargeArray) {
593 Dart_CObject root;
594 root.type = Dart_CObject_kArray;
595 root.value.as_array.length = Array::kMaxElements + 1;
596 root.value.as_array.values = NULL;
597 ExpectEncodeFail(&root);
598 }
599
600
601 TEST_CASE(FailSerializeLargeNestedArray) {
602 Dart_CObject parent;
603 Dart_CObject child;
604 Dart_CObject* values[1] = { &child };
605
606 parent.type = Dart_CObject_kArray;
607 parent.value.as_array.length = 1;
608 parent.value.as_array.values = values;
609 child.type = Dart_CObject_kArray;
610 child.value.as_array.length = Array::kMaxElements + 1;
611 ExpectEncodeFail(&parent);
612 }
613
614
615 TEST_CASE(FailSerializeLargeTypedDataInt8) {
616 Dart_CObject root;
617 root.type = Dart_CObject_kTypedData;
618 root.value.as_typed_data.type = Dart_TypedData_kInt8;
619 root.value.as_typed_data.length =
620 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1;
621 ExpectEncodeFail(&root);
622 }
623
624
625 TEST_CASE(FailSerializeLargeTypedDataUint8) {
626 Dart_CObject root;
627 root.type = Dart_CObject_kTypedData;
628 root.value.as_typed_data.type = Dart_TypedData_kUint8;
629 root.value.as_typed_data.length =
630 TypedData::MaxElements(kTypedDataUint8ArrayCid) + 1;
631 ExpectEncodeFail(&root);
632 }
633
634
635 TEST_CASE(FailSerializeLargeExternalTypedData) {
636 Dart_CObject root;
637 root.type = Dart_CObject_kExternalTypedData;
638 root.value.as_typed_data.length =
639 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1;
640 ExpectEncodeFail(&root);
641 }
642
643
583 TEST_CASE(SerializeEmptyArray) { 644 TEST_CASE(SerializeEmptyArray) {
584 StackZone zone(Isolate::Current()); 645 StackZone zone(Isolate::Current());
585 646
586 // Write snapshot with object content. 647 // Write snapshot with object content.
587 uint8_t* buffer; 648 uint8_t* buffer;
588 MessageWriter writer(&buffer, &zone_allocator); 649 MessageWriter writer(&buffer, &zone_allocator);
589 const int kArrayLength = 0; 650 const int kArrayLength = 0;
590 Array& array = Array::Handle(Array::New(kArrayLength)); 651 Array& array = Array::Handle(Array::New(kArrayLength));
591 writer.WriteMessage(array); 652 writer.WriteMessage(array);
592 intptr_t buffer_len = writer.BytesWritten(); 653 intptr_t buffer_len = writer.BytesWritten();
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 result = Dart_RunLoop(); 2660 result = Dart_RunLoop();
2600 EXPECT(Dart_IsError(result)); 2661 EXPECT(Dart_IsError(result));
2601 EXPECT(Dart_ErrorHasException(result)); 2662 EXPECT(Dart_ErrorHasException(result));
2602 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2663 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2603 Dart_GetError(result)); 2664 Dart_GetError(result));
2604 2665
2605 Dart_ExitScope(); 2666 Dart_ExitScope();
2606 } 2667 }
2607 2668
2608 } // namespace dart 2669 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698