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

Unified Diff: test/cctest/test-api.cc

Issue 2876046: Prevent invalid pre-parsing data passed in through the API from crashing V8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 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 | « src/parser.cc ('k') | test/mjsunit/fuzz-natives.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc (revision 5029)
+++ test/cctest/test-api.cc (working copy)
@@ -8557,6 +8557,43 @@
}
+// Attempts to deserialize bad data.
+TEST(PreCompileInvalidPreparseDataError) {
+ v8::V8::Initialize();
+ v8::HandleScope scope;
+ LocalContext context;
+
+ const char* script = "function foo(){ return 5;}\n"
+ "function bar(){ return 6 + 7;} foo();";
+ v8::ScriptData* sd =
+ v8::ScriptData::PreCompile(script, i::StrLength(script));
+ CHECK(!sd->HasError());
+ // ScriptDataImpl private implementation details
+ const int kUnsignedSize = sizeof(unsigned);
+ const int kHeaderSize = 4;
+ const int kFunctionEntrySize = 4;
+ const int kFunctionEntryStartOffset = 0;
+ const int kFunctionEntryEndOffset = 1;
+ unsigned* sd_data =
+ reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
+ CHECK_EQ(sd->Length(),
+ (kHeaderSize + 2 * kFunctionEntrySize) * kUnsignedSize);
+
+ // Overwrite function bar's end position with 0.
+ sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
+ Local<String> source = String::New(script);
+ Local<Script> compiled_script = Script::New(source, NULL, sd);
+
+ // Overwrite function bar's start position with 200. The function entry
+ // will not be found when searching for it by position.
+ sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
+ 200;
+ compiled_script = Script::New(source, NULL, sd);
+
+ delete sd;
+}
+
+
// Verifies that the Handle<String> and const char* versions of the API produce
// the same results (at least for one trivial case).
TEST(PreCompileAPIVariationsAreSame) {
« no previous file with comments | « src/parser.cc ('k') | test/mjsunit/fuzz-natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698