Commit 29c1c5d6 authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Validate prefixed opcode reads

Identify validation fails to read the index of prefixed opcodes, and not
continue to decode the next bytes.

Change-Id: I2c737af55615ba69ba0c5f5adf18a06c6cdb951a
Bug: chromium:905815
Reviewed-on: https://chromium-review.googlesource.com/c/1390927
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58485}
parent 7ca8acd0
...@@ -1156,6 +1156,7 @@ class WasmDecoder : public Decoder { ...@@ -1156,6 +1156,7 @@ class WasmDecoder : public Decoder {
case kNumericPrefix: { case kNumericPrefix: {
byte numeric_index = byte numeric_index =
decoder->read_u8<validate>(pc + 1, "numeric_index"); decoder->read_u8<validate>(pc + 1, "numeric_index");
if (!VALIDATE(decoder->ok())) return 2;
WasmOpcode opcode = WasmOpcode opcode =
static_cast<WasmOpcode>(kNumericPrefix << 8 | numeric_index); static_cast<WasmOpcode>(kNumericPrefix << 8 | numeric_index);
switch (opcode) { switch (opcode) {
...@@ -1200,6 +1201,7 @@ class WasmDecoder : public Decoder { ...@@ -1200,6 +1201,7 @@ class WasmDecoder : public Decoder {
} }
case kSimdPrefix: { case kSimdPrefix: {
byte simd_index = decoder->read_u8<validate>(pc + 1, "simd_index"); byte simd_index = decoder->read_u8<validate>(pc + 1, "simd_index");
if (!VALIDATE(decoder->ok())) return 2;
WasmOpcode opcode = WasmOpcode opcode =
static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index); static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index);
switch (opcode) { switch (opcode) {
...@@ -1228,6 +1230,7 @@ class WasmDecoder : public Decoder { ...@@ -1228,6 +1230,7 @@ class WasmDecoder : public Decoder {
} }
case kAtomicPrefix: { case kAtomicPrefix: {
byte atomic_index = decoder->read_u8<validate>(pc + 1, "atomic_index"); byte atomic_index = decoder->read_u8<validate>(pc + 1, "atomic_index");
if (!VALIDATE(decoder->ok())) return 2;
WasmOpcode opcode = WasmOpcode opcode =
static_cast<WasmOpcode>(kAtomicPrefix << 8 | atomic_index); static_cast<WasmOpcode>(kAtomicPrefix << 8 | atomic_index);
switch (opcode) { switch (opcode) {
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addType(makeSig([], []));
builder.addType(makeSig([kWasmI32], [kWasmI32]));
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
kExprEnd, // @1
]);
builder.addFunction(undefined, 1 /* sig */)
.addLocals({i32_count: 65})
.addBodyWithEnd([
kExprLoop, kWasmStmt, // @3
kSimdPrefix,
kExprF32x4Min,
kExprI64UConvertI32,
kExprI64RemS,
kExprUnreachable,
kExprLoop, 0x02, // @10
]);
})
...@@ -360,6 +360,7 @@ let kExprI64SExtendI32 = 0xc4; ...@@ -360,6 +360,7 @@ let kExprI64SExtendI32 = 0xc4;
// Prefix opcodes // Prefix opcodes
let kNumericPrefix = 0xfc; let kNumericPrefix = 0xfc;
let kSimdPrefix = 0xfd;
let kAtomicPrefix = 0xfe; let kAtomicPrefix = 0xfe;
// Numeric opcodes. // Numeric opcodes.
...@@ -440,6 +441,9 @@ let kExprI64AtomicCompareExchange8U = 0x4c; ...@@ -440,6 +441,9 @@ let kExprI64AtomicCompareExchange8U = 0x4c;
let kExprI64AtomicCompareExchange16U = 0x4d; let kExprI64AtomicCompareExchange16U = 0x4d;
let kExprI64AtomicCompareExchange32U = 0x4e; let kExprI64AtomicCompareExchange32U = 0x4e;
// Simd opcodes.
let kExprF32x4Min = 0x9e;
let kTrapUnreachable = 0; let kTrapUnreachable = 0;
let kTrapMemOutOfBounds = 1; let kTrapMemOutOfBounds = 1;
let kTrapDivByZero = 2; let kTrapDivByZero = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment