[asm.js] Fix validation failure in module variable import.

R=clemensh@chromium.org
TEST=message/asm-import-wrong-object
BUG=chromium:718653

Change-Id: Ib903d7041ffb6a67c1b3c7be3e0f9455229acd90
Reviewed-on: https://chromium-review.googlesource.com/497747
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45129}
This commit is contained in:
Michael Starzinger 2017-05-05 11:34:42 +02:00 committed by Commit Bot
parent 8833af23e9
commit d380c7da6d
6 changed files with 46 additions and 19 deletions

View File

@ -41,7 +41,6 @@ namespace wasm {
#define FAIL(msg) FAIL_AND_RETURN(, msg) #define FAIL(msg) FAIL_AND_RETURN(, msg)
#define FAILn(msg) FAIL_AND_RETURN(nullptr, msg) #define FAILn(msg) FAIL_AND_RETURN(nullptr, msg)
#define FAILf(msg) FAIL_AND_RETURN(false, msg)
#define EXPECT_TOKEN_OR_RETURN(ret, token) \ #define EXPECT_TOKEN_OR_RETURN(ret, token) \
do { \ do { \
@ -53,7 +52,6 @@ namespace wasm {
#define EXPECT_TOKEN(token) EXPECT_TOKEN_OR_RETURN(, token) #define EXPECT_TOKEN(token) EXPECT_TOKEN_OR_RETURN(, token)
#define EXPECT_TOKENn(token) EXPECT_TOKEN_OR_RETURN(nullptr, token) #define EXPECT_TOKENn(token) EXPECT_TOKEN_OR_RETURN(nullptr, token)
#define EXPECT_TOKENf(token) EXPECT_TOKEN_OR_RETURN(false, token)
#define RECURSE_OR_RETURN(ret, call) \ #define RECURSE_OR_RETURN(ret, call) \
do { \ do { \
@ -67,7 +65,6 @@ namespace wasm {
#define RECURSE(call) RECURSE_OR_RETURN(, call) #define RECURSE(call) RECURSE_OR_RETURN(, call)
#define RECURSEn(call) RECURSE_OR_RETURN(nullptr, call) #define RECURSEn(call) RECURSE_OR_RETURN(nullptr, call)
#define RECURSEf(call) RECURSE_OR_RETURN(false, call)
#define TOK(name) AsmJsScanner::kToken_##name #define TOK(name) AsmJsScanner::kToken_##name
@ -469,8 +466,8 @@ void AsmJsParser::ValidateModuleVar(bool mutable_variable) {
} else if (Check(stdlib_name_)) { } else if (Check(stdlib_name_)) {
EXPECT_TOKEN('.'); EXPECT_TOKEN('.');
RECURSE(ValidateModuleVarStdlib(info)); RECURSE(ValidateModuleVarStdlib(info));
} else if (ValidateModuleVarImport(info, mutable_variable)) { } else if (Peek(foreign_name_) || Peek('+')) {
// Handled inside. RECURSE(ValidateModuleVarImport(info, mutable_variable));
} else if (scanner_.IsGlobal()) { } else if (scanner_.IsGlobal()) {
RECURSE(ValidateModuleVarFromGlobal(info, mutable_variable)); RECURSE(ValidateModuleVarFromGlobal(info, mutable_variable));
} else { } else {
@ -527,32 +524,30 @@ void AsmJsParser::ValidateModuleVarFromGlobal(VarInfo* info,
} }
// 6.1 ValidateModule - foreign imports // 6.1 ValidateModule - foreign imports
bool AsmJsParser::ValidateModuleVarImport(VarInfo* info, void AsmJsParser::ValidateModuleVarImport(VarInfo* info,
bool mutable_variable) { bool mutable_variable) {
if (Check('+')) { if (Check('+')) {
EXPECT_TOKENf(foreign_name_); EXPECT_TOKEN(foreign_name_);
EXPECT_TOKENf('.'); EXPECT_TOKEN('.');
Vector<const char> name = CopyCurrentIdentifierString(); Vector<const char> name = CopyCurrentIdentifierString();
AddGlobalImport(name, AsmType::Double(), kWasmF64, mutable_variable, info); AddGlobalImport(name, AsmType::Double(), kWasmF64, mutable_variable, info);
scanner_.Next(); scanner_.Next();
return true; } else {
} else if (Check(foreign_name_)) { EXPECT_TOKEN(foreign_name_);
EXPECT_TOKENf('.'); EXPECT_TOKEN('.');
Vector<const char> name = CopyCurrentIdentifierString(); Vector<const char> name = CopyCurrentIdentifierString();
scanner_.Next(); scanner_.Next();
if (Check('|')) { if (Check('|')) {
if (!CheckForZero()) { if (!CheckForZero()) {
FAILf("Expected |0 type annotation for foreign integer import"); FAIL("Expected |0 type annotation for foreign integer import");
} }
AddGlobalImport(name, AsmType::Int(), kWasmI32, mutable_variable, info); AddGlobalImport(name, AsmType::Int(), kWasmI32, mutable_variable, info);
return true; } else {
info->kind = VarKind::kImportedFunction;
info->import = new (zone()->New(sizeof(FunctionImportInfo)))
FunctionImportInfo({name, WasmModuleBuilder::SignatureMap(zone())});
} }
info->kind = VarKind::kImportedFunction;
info->import = new (zone()->New(sizeof(FunctionImportInfo)))
FunctionImportInfo({name, WasmModuleBuilder::SignatureMap(zone())});
return true;
} }
return false;
} }
// 6.1 ValidateModule - one variable // 6.1 ValidateModule - one variable

View File

@ -276,7 +276,7 @@ class AsmJsParser {
void ValidateModuleParameters(); void ValidateModuleParameters();
void ValidateModuleVars(); void ValidateModuleVars();
void ValidateModuleVar(bool mutable_variable); void ValidateModuleVar(bool mutable_variable);
bool ValidateModuleVarImport(VarInfo* info, bool mutable_variable); void ValidateModuleVarImport(VarInfo* info, bool mutable_variable);
void ValidateModuleVarStdlib(VarInfo* info); void ValidateModuleVarStdlib(VarInfo* info);
void ValidateModuleVarNewStdlib(VarInfo* info); void ValidateModuleVarNewStdlib(VarInfo* info);
void ValidateModuleVarFromGlobal(VarInfo* info, bool mutable_variable); void ValidateModuleVarFromGlobal(VarInfo* info, bool mutable_variable);

View File

@ -0,0 +1,11 @@
// Copyright 2017 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.
// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages
function Module(stdlib, foreign, heap) {
"use asm"
var x = foreign.x | 1;
}
Module(this, { x:0 });

View File

@ -0,0 +1,5 @@
# Copyright 2017 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.
*%(basename)s:9: Invalid asm.js: Expected |0 type annotation for foreign integer import

View File

@ -0,0 +1,11 @@
// Copyright 2017 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.
// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages
function Module(stdlib, foreign, heap) {
"use asm"
var x = +stdlib.x;
}
Module(this, { x:0 });

View File

@ -0,0 +1,5 @@
# Copyright 2017 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.
*%(basename)s:9: Invalid asm.js: Unexpected token