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

Unified Diff: src/serialize.cc

Issue 394793002: Verify that source string matches serialized code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index eedbab4cd6e0f50053288dfa73d2f69056f9a2da..6937e5b1d918efc5a8015cd3cfe3a00f26ba5815 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -13,6 +13,7 @@
#include "src/global-handles.h"
#include "src/ic-inl.h"
#include "src/natives.h"
+#include "src/objects.h"
#include "src/runtime.h"
#include "src/serialize.h"
#include "src/snapshot.h"
@@ -1993,7 +1994,7 @@ void CodeSerializer::SerializeSourceObject(HowToCode how_to_code,
Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate,
ScriptData* data,
Handle<String> source) {
- SerializedCodeData scd(data);
+ SerializedCodeData scd(data, *source);
SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
Deserializer deserializer(&payload);
STATIC_ASSERT(NEW_SPACE == 0);
@@ -2017,6 +2018,7 @@ Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate,
SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs)
: owns_script_data_(true) {
+ DisallowHeapAllocation no_gc;
int data_length = payload->length() + kHeaderEntries * kIntSize;
byte* data = NewArray<byte>(data_length);
ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
@@ -2024,7 +2026,7 @@ SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs)
static_cast<size_t>(payload->length()));
script_data_ = new ScriptData(data, data_length);
script_data_->AcquireDataOwnership();
- SetHeaderValue(kVersionHashOffset, Version::Hash());
+ SetHeaderValue(kCheckSumOffset, CheckSum(cs->source()));
STATIC_ASSERT(NEW_SPACE == 0);
for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i));
@@ -2032,8 +2034,18 @@ SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs)
}
-bool SerializedCodeData::IsSane() {
- return GetHeaderValue(kVersionHashOffset) == Version::Hash() &&
+bool SerializedCodeData::IsSane(String* source) {
+ return GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
PayloadLength() >= SharedFunctionInfo::kSize;
}
+
+
+int SerializedCodeData::CheckSum(String* string) {
+ int checksum = Version::Hash();
+#ifdef DEBUG
+ uint32_t seed = static_cast<uint32_t>(checksum);
+ checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed));
+#endif // DEBUG
+ return checksum;
+}
} } // namespace v8::internal
« no previous file with comments | « src/serialize.h ('k') | test/cctest/test-serialize.cc » ('j') | test/cctest/test-serialize.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698