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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10829444: Avoid trusting the length encoded in the Snapshot if there is an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 10993)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -823,8 +823,7 @@
// Since this is only a snapshot the root library should not be set.
isolate->object_store()->set_root_library(Library::Handle(isolate));
SnapshotWriter writer(Snapshot::kFull, buffer, ApiReallocate);
- writer.WriteFullSnapshot();
- *size = writer.BytesWritten();
+ *size = writer.WriteFullSnapshot();
siva 2012/08/22 23:30:39 I would prefer not returning the size as a return
turnidge 2012/08/23 18:37:57 Done.
return Api::Success(isolate);
}
@@ -852,8 +851,7 @@
CURRENT_FUNC);
}
ScriptSnapshotWriter writer(buffer, ApiReallocate);
- writer.WriteScriptSnapshot(library);
- *size = writer.BytesWritten();
+ *size = writer.WriteScriptSnapshot(library);
return Api::Success(isolate);
}
@@ -954,11 +952,12 @@
uint8_t* buffer = NULL;
ApiMessageWriter writer(&buffer, &allocator);
- writer.WriteMessage(len, data);
+ intptr_t buffer_len = writer.WriteMessage(len, data);
// Post the message at the given port.
return PortMap::PostMessage(new Message(
- port_id, Message::kIllegalPort, buffer, Message::kNormalPriority));
+ port_id, Message::kIllegalPort, buffer, buffer_len,
+ Message::kNormalPriority));
}
@@ -966,11 +965,12 @@
uint8_t* buffer = NULL;
ApiMessageWriter writer(&buffer, allocator);
- writer.WriteCMessage(message);
+ intptr_t buffer_len = writer.WriteCMessage(message);
// Post the message at the given port.
return PortMap::PostMessage(new Message(
- port_id, Message::kIllegalPort, buffer, Message::kNormalPriority));
+ port_id, Message::kIllegalPort, buffer, buffer_len,
+ Message::kNormalPriority));
}
@@ -982,9 +982,9 @@
uint8_t* data = NULL;
SnapshotWriter writer(Snapshot::kMessage, &data, &allocator);
writer.WriteObject(object.raw());
- writer.FinalizeBuffer();
+ intptr_t len = writer.FinalizeBuffer();
return PortMap::PostMessage(new Message(
- port_id, Message::kIllegalPort, data, Message::kNormalPriority));
+ port_id, Message::kIllegalPort, data, len, Message::kNormalPriority));
}
@@ -3783,10 +3783,15 @@
if (buffer == NULL) {
RETURN_NULL_ERROR(buffer);
}
- const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
+ const Snapshot* snapshot =
+ Snapshot::SetupFromBuffer(buffer, Snapshot::kTrustedLength);
+ if (snapshot == NULL) {
+ return Api::NewError("%s: unexpected error during snapshot parsing."
+ " snapshot", CURRENT_FUNC);
+ }
if (!snapshot->IsScriptSnapshot()) {
return Api::NewError("%s expects parameter 'buffer' to be a script type"
- " snapshot", CURRENT_FUNC);
+ " snapshot.", CURRENT_FUNC);
}
Library& library =
Library::Handle(isolate, isolate->object_store()->root_library());

Powered by Google App Engine
This is Rietveld 408576698