memory-maximum-clamping.js (1034B)
1 const MemoryMaxValid = 65536; 2 3 // Linking should fail if the imported memory has a higher maximum than required, 4 // however if we internally clamp maximum values to an implementation limit 5 // and use that for linking we may erroneously accept some modules. 6 7 function testLinkFail(importMax, importedMax) { 8 assertErrorMessage(() => { 9 let importedMemory = new WebAssembly.Memory({ 10 initial: 0, 11 maximum: importedMax, 12 }); 13 wasmEvalText(`(module 14 (memory (import "" "") 0 ${importMax}) 15 )`, {"": {"": importedMemory}}); 16 }, WebAssembly.LinkError, /incompatible maximum/); 17 } 18 19 testLinkFail(0, 1); 20 testLinkFail(MemoryMaxValid - 1, MemoryMaxValid); 21 22 // The type reflection interface for WebAssembly.Memory should not report 23 // an internally clamped maximum. 24 25 if ('type' in WebAssembly.Memory.prototype) { 26 let memory = new WebAssembly.Memory({ 27 initial: 0, 28 maximum: MemoryMaxValid, 29 }); 30 let type = memory.type(); 31 assertEq(type.maximum, MemoryMaxValid, 'reported memory maximum is not clamped'); 32 }