Commit 80caaac3 authored by mtrofin's avatar mtrofin Committed by Commit bot

[wasm] test deserialization when header is invalid

A test where the deserialization data has a header, but the
header is invalid. This is in addition to the current test
where we have empty deserialization data.

BUG=

Review-Url: https://codereview.chromium.org/2418483002
Cr-Commit-Position: refs/heads/master@{#40321}
parent 36532619
......@@ -96,6 +96,31 @@ class SerializedCodeData : public SerializedData {
INVALID_HEADER = 7
};
// The data header consists of uint32_t-sized entries:
// [0] magic number and external reference count
// [1] version hash
// [2] source hash
// [3] cpu features
// [4] flag hash
// [5] number of code stub keys
// [6] number of reservation size entries
// [7] payload length
// [8] payload checksum part 1
// [9] payload checksum part 2
// ... reservations
// ... code stub keys
// ... serialized payload
static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size;
static const int kSourceHashOffset = kVersionHashOffset + kInt32Size;
static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size;
static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size;
static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size;
static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
static const int kHeaderSize = kChecksum2Offset + kInt32Size;
// Used when consuming.
static const SerializedCodeData FromCachedData(
Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash,
......@@ -125,30 +150,6 @@ class SerializedCodeData : public SerializedData {
SanityCheckResult SanityCheck(Isolate* isolate,
uint32_t expected_source_hash) const;
// The data header consists of uint32_t-sized entries:
// [0] magic number and external reference count
// [1] version hash
// [2] source hash
// [3] cpu features
// [4] flag hash
// [5] number of code stub keys
// [6] number of reservation size entries
// [7] payload length
// [8] payload checksum part 1
// [9] payload checksum part 2
// ... reservations
// ... code stub keys
// ... serialized payload
static const int kVersionHashOffset = kMagicNumberOffset + kInt32Size;
static const int kSourceHashOffset = kVersionHashOffset + kInt32Size;
static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size;
static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size;
static const int kNumReservationsOffset = kFlagHashOffset + kInt32Size;
static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
static const int kHeaderSize = kChecksum2Offset + kInt32Size;
};
} // namespace internal
......
......@@ -5,6 +5,8 @@
#include <stdlib.h>
#include <string.h>
#include "src/snapshot/code-serializer.h"
#include "src/version.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module-builder.h"
......@@ -228,9 +230,16 @@ TEST(Run_WasmModule_Serialization) {
create_params.array_buffer_allocator =
CcTest::InitIsolateOnce()->array_buffer_allocator();
for (int i = 0; i < 2; ++i) {
for (int i = 0; i < 3; ++i) {
v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
if (i == 1) {
// Invalidate the header by providing a mismatched version
uint32_t* buffer = reinterpret_cast<uint32_t*>(
const_cast<uint8_t*>(serialized_bytes.first));
buffer[SerializedCodeData::kVersionHashOffset] = Version::Hash() + 1;
}
if (i == 2) {
// Provide no serialized data to force recompilation.
serialized_bytes.first = nullptr;
serialized_bytes.second = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment