Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: test/mjsunit/regress/wasm/regression-684858.js

Issue 2656713003: [wasm] Fix check failure on invalid name section (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
OLDNEW
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698