Skip to content

Commit 1dd2bc1

Browse files
committed
review: fix style and remove redundant WasmHeader check
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 808a869 commit 1dd2bc1

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

src/common/bytecode_util.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace proxy_wasm {
1919
namespace common {
2020

2121
bool BytecodeUtil::checkWasmHeader(std::string_view bytecode) {
22+
// Wasm file header is 8 bytes (magic number + version).
2223
static const uint8_t wasm_magic_number[4] = {0x00, 0x61, 0x73, 0x6d};
2324
return bytecode.size() < 8 || !::memcmp(bytecode.data(), wasm_magic_number, 4);
2425
}
@@ -29,6 +30,7 @@ bool BytecodeUtil::getAbiVersion(std::string_view bytecode, proxy_wasm::AbiVersi
2930
if (!checkWasmHeader(bytecode)) {
3031
return false;
3132
}
33+
3234
// Skip the Wasm header.
3335
const char *pos = bytecode.data() + 8;
3436
const char *end = bytecode.data() + bytecode.size();

src/common/bytecode_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class BytecodeUtil {
3333
static bool checkWasmHeader(std::string_view bytecode);
3434

3535
/**
36-
* checkWasmHeader extracts ABI version from the bytecode.
36+
* getAbiVersion extracts ABI version from the bytecode.
3737
* @param bytecode is the target bytecode.
38-
* @param ret is the reference to store the extracted ABI version or UnKnonw if it doesn't exist.
38+
* @param ret is the reference to store the extracted ABI version or UnKnown if it doesn't exist.
3939
* @return indicates whether parsing succeeded or not.
4040
*/
4141
static bool getAbiVersion(std::string_view bytecode, proxy_wasm::AbiVersion &ret);

src/v8/v8.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,6 @@ template <typename T, typename U> constexpr T convertValTypesToArgsTuple(const U
254254
bool V8::load(const std::string &code, bool allow_precompiled) {
255255
store_ = wasm::Store::make(engine());
256256

257-
// Wasm file header is 8 bytes (magic number + version).
258-
if (!common::BytecodeUtil::checkWasmHeader(code)) {
259-
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
260-
return false;
261-
}
262-
263257
// Get ABI version from bytecode.
264258
if (!common::BytecodeUtil::getAbiVersion(code, abi_version_)) {
265259
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");

src/wasmtime/wasmtime.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ class Wasmtime : public WasmVm {
115115
bool Wasmtime::load(const std::string &code, bool allow_precompiled) {
116116
store_ = wasm_store_new(engine());
117117

118-
if (!common::BytecodeUtil::checkWasmHeader(code)) {
119-
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
120-
return false;
121-
}
122-
123118
// Get ABI version from bytecode.
124119
if (!common::BytecodeUtil::getAbiVersion(code, abi_version_)) {
125120
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");

0 commit comments

Comments
 (0)