MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / checkValidWasmCode

Function checkValidWasmCode

src/Interpreters/WasmModuleManager.cpp:91–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91static std::expected<void, PreformattedMessage> checkValidWasmCode(std::string_view name, std::string_view wasm_code)
92{
93 if (name.empty() || 128 < name.size() || !std::all_of(name.data(), name.data() + name.size(), isWordCharASCII))
94 {
95 return formatUnexpected(
96 "Name of a WebAssembly module must be a non-empty string of length at most 128 consisting of word characters only, got '{}'",
97 trimAndEscape(name));
98 }
99
100 /// Detect magic number for WebAssembly module
101 /// Reference: https://webassembly.github.io/spec/core/binary/modules.html#binary-module
102 constexpr std::array<uint8_t, 8> wasm_magic_number = {0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00};
103 if (!std::ranges::equal(wasm_magic_number, std::views::take(wasm_code, wasm_magic_number.size())))
104 {
105 return formatUnexpected(
106 "Cannot read magic number for WebAssembly module '{}', binary module version 0x1 is expected, got '{}'",
107 name, trimAndEscape(wasm_code, 16));
108 }
109
110 return {};
111}
112
113static std::expected<String, PreformattedMessage> validateModuleFile(const DiskPtr & user_scripts_disk, const String & path)
114{

Callers 2

validateModuleFileFunction · 0.85
saveModuleMethod · 0.85

Calls 5

formatUnexpectedFunction · 0.85
trimAndEscapeFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected