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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 1125073004: Prevent stack overflow in the serializer/deserializer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixed all Created 5 years, 7 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
« no previous file with comments | « src/snapshot/serialize.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 2007-2010 the V8 project authors. All rights reserved. 1 // Copyright 2007-2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 SnapshotByteSink startup_sink; 323 SnapshotByteSink startup_sink;
324 StartupSerializer startup_serializer(isolate, &startup_sink); 324 StartupSerializer startup_serializer(isolate, &startup_sink);
325 startup_serializer.SerializeStrongReferences(); 325 startup_serializer.SerializeStrongReferences();
326 326
327 SnapshotByteSink partial_sink; 327 SnapshotByteSink partial_sink;
328 PartialSerializer partial_serializer(isolate, &startup_serializer, 328 PartialSerializer partial_serializer(isolate, &startup_serializer,
329 &partial_sink); 329 &partial_sink);
330 partial_serializer.Serialize(&raw_foo); 330 partial_serializer.Serialize(&raw_foo);
331 331
332 startup_serializer.SerializeWeakReferences(); 332 startup_serializer.SerializeWeakReferencesAndDeferred();
333 333
334 SnapshotData startup_snapshot(startup_serializer); 334 SnapshotData startup_snapshot(startup_serializer);
335 SnapshotData partial_snapshot(partial_serializer); 335 SnapshotData partial_snapshot(partial_serializer);
336 336
337 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 337 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
338 WritePayload(startup_snapshot.RawData(), startup_name.start()); 338 WritePayload(startup_snapshot.RawData(), startup_name.start());
339 339
340 startup_name.Dispose(); 340 startup_name.Dispose();
341 } 341 }
342 v8_isolate->Exit(); 342 v8_isolate->Exit();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 env.Reset(); 440 env.Reset();
441 441
442 SnapshotByteSink startup_sink; 442 SnapshotByteSink startup_sink;
443 StartupSerializer startup_serializer(isolate, &startup_sink); 443 StartupSerializer startup_serializer(isolate, &startup_sink);
444 startup_serializer.SerializeStrongReferences(); 444 startup_serializer.SerializeStrongReferences();
445 445
446 SnapshotByteSink partial_sink; 446 SnapshotByteSink partial_sink;
447 PartialSerializer partial_serializer(isolate, &startup_serializer, 447 PartialSerializer partial_serializer(isolate, &startup_serializer,
448 &partial_sink); 448 &partial_sink);
449 partial_serializer.Serialize(&raw_context); 449 partial_serializer.Serialize(&raw_context);
450 startup_serializer.SerializeWeakReferences(); 450 startup_serializer.SerializeWeakReferencesAndDeferred();
451 451
452 SnapshotData startup_snapshot(startup_serializer); 452 SnapshotData startup_snapshot(startup_serializer);
453 SnapshotData partial_snapshot(partial_serializer); 453 SnapshotData partial_snapshot(partial_serializer);
454 454
455 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 455 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
456 WritePayload(startup_snapshot.RawData(), startup_name.start()); 456 WritePayload(startup_snapshot.RawData(), startup_name.start());
457 457
458 startup_name.Dispose(); 458 startup_name.Dispose();
459 } 459 }
460 v8_isolate->Dispose(); 460 v8_isolate->Dispose();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 env.Reset(); 575 env.Reset();
576 576
577 SnapshotByteSink startup_sink; 577 SnapshotByteSink startup_sink;
578 StartupSerializer startup_serializer(isolate, &startup_sink); 578 StartupSerializer startup_serializer(isolate, &startup_sink);
579 startup_serializer.SerializeStrongReferences(); 579 startup_serializer.SerializeStrongReferences();
580 580
581 SnapshotByteSink partial_sink; 581 SnapshotByteSink partial_sink;
582 PartialSerializer partial_serializer(isolate, &startup_serializer, 582 PartialSerializer partial_serializer(isolate, &startup_serializer,
583 &partial_sink); 583 &partial_sink);
584 partial_serializer.Serialize(&raw_context); 584 partial_serializer.Serialize(&raw_context);
585 startup_serializer.SerializeWeakReferences(); 585 startup_serializer.SerializeWeakReferencesAndDeferred();
586 586
587 SnapshotData startup_snapshot(startup_serializer); 587 SnapshotData startup_snapshot(startup_serializer);
588 SnapshotData partial_snapshot(partial_serializer); 588 SnapshotData partial_snapshot(partial_serializer);
589 589
590 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 590 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
591 WritePayload(startup_snapshot.RawData(), startup_name.start()); 591 WritePayload(startup_snapshot.RawData(), startup_name.start());
592 592
593 startup_name.Dispose(); 593 startup_name.Dispose();
594 } 594 }
595 v8_isolate->Dispose(); 595 v8_isolate->Dispose();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 v8::HandleScope h_scope(isolate1); 731 v8::HandleScope h_scope(isolate1);
732 v8::Local<v8::Context> context = v8::Context::New(isolate1); 732 v8::Local<v8::Context> context = v8::Context::New(isolate1);
733 delete[] data1.data; // We can dispose of the snapshot blob now. 733 delete[] data1.data; // We can dispose of the snapshot blob now.
734 v8::Context::Scope c_scope(context); 734 v8::Context::Scope c_scope(context);
735 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value()); 735 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value());
736 } 736 }
737 isolate1->Dispose(); 737 isolate1->Dispose();
738 } 738 }
739 739
740 740
741 TEST(SnapshotBlobsStackOverflow) {
742 DisableTurbofan();
743 const char* source =
744 "var a = [0];"
745 "var b = a;"
746 "for (var i = 0; i < 10000; i++) {"
747 " var c = [i];"
748 " b.push(c);"
749 " b.push(c);"
750 " b = c;"
751 "}";
752
753 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source);
754
755 v8::Isolate::CreateParams params;
756 params.snapshot_blob = &data;
757 params.array_buffer_allocator = CcTest::array_buffer_allocator();
758
759 v8::Isolate* isolate = v8::Isolate::New(params);
760 {
761 v8::Isolate::Scope i_scope(isolate);
762 v8::HandleScope h_scope(isolate);
763 v8::Local<v8::Context> context = v8::Context::New(isolate);
764 delete[] data.data; // We can dispose of the snapshot blob now.
765 v8::Context::Scope c_scope(context);
766 const char* test =
767 "var sum = 0;"
768 "while (a) {"
769 " sum += a[0];"
770 " a = a[1];"
771 "}"
772 "sum";
773 CHECK_EQ(9999 * 5000, CompileRun(test)->ToInt32(isolate)->Int32Value());
774 }
775 isolate->Dispose();
776 }
777
778
741 TEST(TestThatAlwaysSucceeds) { 779 TEST(TestThatAlwaysSucceeds) {
742 } 780 }
743 781
744 782
745 TEST(TestThatAlwaysFails) { 783 TEST(TestThatAlwaysFails) {
746 bool ArtificialFailure = false; 784 bool ArtificialFailure = false;
747 CHECK(ArtificialFailure); 785 CHECK(ArtificialFailure);
748 } 786 }
749 787
750 788
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 isolate->Dispose(); 1607 isolate->Dispose();
1570 } 1608 }
1571 1609
1572 1610
1573 TEST(SerializationMemoryStats) { 1611 TEST(SerializationMemoryStats) {
1574 FLAG_profile_deserialization = true; 1612 FLAG_profile_deserialization = true;
1575 FLAG_always_opt = false; 1613 FLAG_always_opt = false;
1576 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 1614 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
1577 delete[] blob.data; 1615 delete[] blob.data;
1578 } 1616 }
OLDNEW
« no previous file with comments | « src/snapshot/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698