diff --git a/src/serialize.cc b/src/serialize.cc index 5b1f6e5407..2ea09f89c3 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -1618,7 +1618,7 @@ void Serializer::Pad() { bool SnapshotByteSource::AtEOF() { - if (0u + length_ - position_ > sizeof(uint32_t)) return false; + if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; for (int x = position_; x < length_; x++) { if (data_[x] != SerializerDeserializer::nop()) return false; } diff --git a/src/snapshot-common.cc b/src/snapshot-common.cc index cf93e92240..a8806f053f 100644 --- a/src/snapshot-common.cc +++ b/src/snapshot-common.cc @@ -86,10 +86,13 @@ bool Snapshot::Initialize(const char* snapshot_file) { int len; byte* str = ReadBytes(snapshot_file, &len); if (!str) return false; - SnapshotByteSource source(str, len); - Deserializer deserializer(&source); - ReserveSpaceForSnapshot(&deserializer, snapshot_file); - bool success = V8::Initialize(&deserializer); + bool success; + { + SnapshotByteSource source(str, len); + Deserializer deserializer(&source); + ReserveSpaceForSnapshot(&deserializer, snapshot_file); + success = V8::Initialize(&deserializer); + } DeleteArray(str); return success; } else if (size_ > 0) {