Commit 1f6f345d authored by aseemgarg's avatar aseemgarg Committed by Commit bot

[wasm] fix simd opcode read and error case for bad simd opcodes

BUG=chromium:658426
R=ahaas@chromium.org,titzer@chromium.org,gdeepti@chromium.org

Review-Url: https://codereview.chromium.org/2447683004
Cr-Commit-Position: refs/heads/master@{#40572}
parent e645b560
...@@ -324,7 +324,7 @@ class WasmDecoder : public Decoder { ...@@ -324,7 +324,7 @@ class WasmDecoder : public Decoder {
case kExprF64Const: case kExprF64Const:
return 9; return 9;
case kSimdPrefix: { case kSimdPrefix: {
byte simd_index = *(pc + 1); byte simd_index = checked_read_u8(pc, 1, "simd_index");
WasmOpcode opcode = WasmOpcode opcode =
static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index); static_cast<WasmOpcode>(kSimdPrefix << 8 | simd_index);
switch (opcode) { switch (opcode) {
...@@ -341,7 +341,8 @@ class WasmDecoder : public Decoder { ...@@ -341,7 +341,8 @@ class WasmDecoder : public Decoder {
return 3; return 3;
} }
default: default:
UNREACHABLE(); error("invalid SIMD opcode");
return 2;
} }
} }
default: default:
...@@ -1139,7 +1140,7 @@ class WasmFullDecoder : public WasmDecoder { ...@@ -1139,7 +1140,7 @@ class WasmFullDecoder : public WasmDecoder {
case kSimdPrefix: { case kSimdPrefix: {
CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype);
len++; len++;
byte simd_index = *(pc_ + 1); byte simd_index = checked_read_u8(pc_, 1, "simd index");
opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index);
TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix,
simd_index, WasmOpcodes::ShortOpcodeName(opcode)); simd_index, WasmOpcodes::ShortOpcodeName(opcode));
......
...@@ -2500,6 +2500,19 @@ TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { ...@@ -2500,6 +2500,19 @@ TEST_F(WasmOpcodeLengthTest, SimpleExpressions) {
EXPECT_LENGTH(1, kExprI64ReinterpretF64); EXPECT_LENGTH(1, kExprI64ReinterpretF64);
} }
TEST_F(WasmOpcodeLengthTest, SimdExpressions) {
#define TEST_SIMD(name, opcode, sig) \
EXPECT_LENGTH_N(2, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff));
FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD)
#undef TEST_SIMD
#define TEST_SIMD(name, opcode, sig) \
EXPECT_LENGTH_N(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff));
FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD)
#undef TEST_SIMD
// test for bad simd opcode
EXPECT_LENGTH_N(2, kSimdPrefix, 0xff);
}
typedef ZoneVector<LocalType> LocalTypeMap; typedef ZoneVector<LocalType> LocalTypeMap;
class LocalDeclDecoderTest : public TestWithZone { class LocalDeclDecoderTest : public TestWithZone {
......
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