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

Unified Diff: runtime/vm/snapshot_test.cc

Issue 23532048: Checks for valid CObject lengths in native API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot_test.cc
diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc
index 0aac46188161548b76891dd2ffcf28f9c38a6f8c..fdcf6c027809cf135dd45fd9d83da584780eb27e 100644
--- a/runtime/vm/snapshot_test.cc
+++ b/runtime/vm/snapshot_test.cc
@@ -131,6 +131,15 @@ static void CheckEncodeDecodeMessage(Dart_CObject* root) {
CompareDartCObjects(root, new_root);
}
+
+static void ExpectEncodeFail(Dart_CObject* root) {
+ uint8_t* buffer = NULL;
+ ApiMessageWriter writer(&buffer, &malloc_allocator);
+ const bool result = writer.WriteCMessage(root);
+ EXPECT_EQ(false, result);
+}
+
+
TEST_CASE(SerializeNull) {
StackZone zone(Isolate::Current());
@@ -580,6 +589,58 @@ TEST_CASE(SerializeArray) {
}
+TEST_CASE(FailSerializeLargeArray) {
+ Dart_CObject root;
+ root.type = Dart_CObject_kArray;
+ root.value.as_array.length = Array::kMaxElements + 1;
+ root.value.as_array.values = NULL;
+ ExpectEncodeFail(&root);
+}
+
+
+TEST_CASE(FailSerializeLargeNestedArray) {
+ Dart_CObject parent;
+ Dart_CObject child;
+ Dart_CObject* values[1] = { &child };
+
+ parent.type = Dart_CObject_kArray;
+ parent.value.as_array.length = 1;
+ parent.value.as_array.values = values;
+ child.type = Dart_CObject_kArray;
+ child.value.as_array.length = Array::kMaxElements + 1;
+ ExpectEncodeFail(&parent);
+}
+
+
+TEST_CASE(FailSerializeLargeTypedDataInt8) {
+ Dart_CObject root;
+ root.type = Dart_CObject_kTypedData;
+ root.value.as_typed_data.type = Dart_TypedData_kInt8;
+ root.value.as_typed_data.length =
+ TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1;
+ ExpectEncodeFail(&root);
+}
+
+
+TEST_CASE(FailSerializeLargeTypedDataUint8) {
+ Dart_CObject root;
+ root.type = Dart_CObject_kTypedData;
+ root.value.as_typed_data.type = Dart_TypedData_kUint8;
+ root.value.as_typed_data.length =
+ TypedData::MaxElements(kTypedDataUint8ArrayCid) + 1;
+ ExpectEncodeFail(&root);
+}
+
+
+TEST_CASE(FailSerializeLargeExternalTypedData) {
+ Dart_CObject root;
+ root.type = Dart_CObject_kExternalTypedData;
+ root.value.as_typed_data.length =
+ ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1;
+ ExpectEncodeFail(&root);
+}
+
+
TEST_CASE(SerializeEmptyArray) {
StackZone zone(Isolate::Current());
« 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