OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 load('test/mjsunit/wasm/wasm-constants.js'); |
| 6 load('test/mjsunit/wasm/wasm-module-builder.js'); |
| 7 |
| 8 var name = 'regression_684858'; |
| 9 |
| 10 function patchNameLength(buffer) { |
| 11 var count = 0; |
| 12 var view = new Uint8Array(buffer); |
| 13 for (var i = 0, e = view.length - name.length; i < e; ++i) { |
| 14 var subs = String.fromCharCode.apply(null, view.slice(i, i + name.length)); |
| 15 if (subs != name) continue; |
| 16 ++count; |
| 17 // One byte before this name, its length is encoded. |
| 18 // Patch this to 127, making it out of bounds. |
| 19 if (view.length >= 127) throw Error('cannot patch reliably'); |
| 20 if (view[i - 1] != name.length) throw Error('unexpected length'); |
| 21 view[i - 1] = 0x7f; |
| 22 } |
| 23 if (count != 1) throw Error('did not find name'); |
| 24 } |
| 25 |
| 26 var builder = new WasmModuleBuilder(); |
| 27 builder.addFunction(name, kSig_i_v) |
| 28 .addBody([kExprI32Const, 2, kExprI32Const, 0, kExprI32DivU]) |
| 29 .exportAs('main'); |
| 30 var buffer = builder.toBuffer(); |
| 31 patchNameLength(buffer); |
| 32 var module = new WebAssembly.Module(buffer); |
| 33 var instance = new WebAssembly.Instance(module); |
| 34 assertThrows(() => instance.exports.main(), WebAssembly.RuntimeError); |
OLD | NEW |