Commit dffc2a5a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix and verify size of serialized modules

R=mstarzinger@chromium.org

Change-Id: I5b062da2b4717f7247ea61d1118f0466c7b0474c
Reviewed-on: https://chromium-review.googlesource.com/1097322Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53674}
parent 4da05e97
...@@ -192,7 +192,7 @@ uint32_t GetWasmCalleeTag(RelocInfo* rinfo) { ...@@ -192,7 +192,7 @@ uint32_t GetWasmCalleeTag(RelocInfo* rinfo) {
constexpr size_t kHeaderSize = constexpr size_t kHeaderSize =
sizeof(uint32_t) + // total wasm function count sizeof(uint32_t) + // total wasm function count
sizeof(uint32_t); // imported functions - i.e. index of first wasm function sizeof(uint32_t); // imported functions (index of first wasm function)
constexpr size_t kCodeHeaderSize = constexpr size_t kCodeHeaderSize =
sizeof(size_t) + // size of code section sizeof(size_t) + // size of code section
...@@ -406,13 +406,15 @@ bool SerializeNativeModule(Isolate* isolate, ...@@ -406,13 +406,15 @@ bool SerializeNativeModule(Isolate* isolate,
Vector<byte> buffer) { Vector<byte> buffer) {
NativeModule* native_module = compiled_module->GetNativeModule(); NativeModule* native_module = compiled_module->GetNativeModule();
NativeModuleSerializer serializer(isolate, native_module); NativeModuleSerializer serializer(isolate, native_module);
size_t measured_size = serializer.Measure(); size_t measured_size = kVersionSize + serializer.Measure();
if (buffer.size() < measured_size) return false; if (buffer.size() < measured_size) return false;
Writer writer(buffer); Writer writer(buffer);
WriteVersion(isolate, &writer); WriteVersion(isolate, &writer);
return serializer.Write(&writer); if (!serializer.Write(&writer)) return false;
DCHECK_EQ(measured_size, writer.bytes_written());
return true;
} }
class V8_EXPORT_PRIVATE NativeModuleDeserializer { class V8_EXPORT_PRIVATE NativeModuleDeserializer {
......
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