Add Chromium-only Blender WebEngine parity work
This commit is contained in:
37
tools/web/check-malicious-blends.mjs
Normal file
37
tools/web/check-malicious-blends.mjs
Normal file
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import factory from "../../web/app/src/vendor/blender/web_engine.js";
|
||||
|
||||
const wasmBinary = fs.readFileSync(new URL("../../web/app/src/vendor/blender/web_engine.wasm", import.meta.url));
|
||||
const valid = fs.readFileSync(new URL("../../tests/files/web/basic_scene.blend", import.meta.url));
|
||||
const encoder = new TextEncoder();
|
||||
const cases = [
|
||||
{ name: "empty", bytes: new Uint8Array(0) },
|
||||
{ name: "random", bytes: Uint8Array.from({ length: 4096 }, (_, index) => (index * 73 + 19) & 0xff) },
|
||||
{ name: "truncated-header", bytes: valid.subarray(0, 11) },
|
||||
{ name: "truncated-dna", bytes: valid.subarray(0, Math.min(8192, valid.length - 1)) },
|
||||
{ name: "forged-block-size", bytes: (() => { const data = new Uint8Array(64); data.set(encoder.encode("BLENDER-v520")); data.set(encoder.encode("TEST"), 12); data.set([0xff, 0xff, 0xff, 0x7f], 16); return data; })() },
|
||||
];
|
||||
|
||||
for (const fixture of cases) {
|
||||
const engine = await factory({ wasmBinary });
|
||||
const handle = engine._web_engine_create();
|
||||
assert.ok(handle > 0);
|
||||
try {
|
||||
let pointer = 0;
|
||||
if (fixture.bytes.byteLength > 0) {
|
||||
pointer = engine._malloc(fixture.bytes.byteLength);
|
||||
engine.HEAPU8.set(fixture.bytes, pointer);
|
||||
}
|
||||
const result = engine._web_engine_open_blend(handle, pointer, fixture.bytes.byteLength);
|
||||
if (pointer) engine._free(pointer);
|
||||
assert.notEqual(result, 0, `${fixture.name} malicious blend was accepted`);
|
||||
const message = engine.UTF8ToString(engine._web_engine_last_error_message());
|
||||
assert.ok(message.length > 0 && message.length < 1024, `${fixture.name} did not return a bounded structured error`);
|
||||
}
|
||||
finally {
|
||||
engine._web_engine_destroy(handle);
|
||||
}
|
||||
}
|
||||
|
||||
process.stdout.write(`malicious-blends-ok rejected=${cases.length}\n`);
|
||||
Reference in New Issue
Block a user