Socket
Socket
Sign inDemoInstall

@webassemblyjs/validation

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webassemblyjs/validation - npm Package Compare versions

Comparing version 1.5.1 to 1.5.2

3

lib/index.js

@@ -27,4 +27,2 @@ "use strict";

var _mutGlobal = _interopRequireDefault(require("./mut-global"));
var _importOrder = _interopRequireDefault(require("./import-order"));

@@ -44,3 +42,2 @@

var errors = [];
errors.push.apply(errors, _toConsumableArray((0, _mutGlobal.default)(ast)));
errors.push.apply(errors, _toConsumableArray((0, _importOrder.default)(ast)));

@@ -47,0 +44,0 @@ errors.push.apply(errors, _toConsumableArray((0, _typeChecker.default)(ast)));

22

lib/type-checker.js

@@ -123,3 +123,3 @@ "use strict";

if (stopFuncCheck) {
return;
return errors;
} // Compare the two

@@ -134,2 +134,9 @@

function isEmptyStack(stack) {
// Polymorphic types are allowed in empty stack
return stack.filter(function (t) {
return t !== _types.POLYMORPHIC;
}).length === 0;
}
function checkStacks(expectedStack, actualStack) {

@@ -152,3 +159,3 @@ if (actualStack !== false) {

if (j >= 0) {
if (!isEmptyStack(actualStack.slice(0, j + 1))) {
errors.push("Stack contains additional type ".concat(actualStack.slice(0, j + 1), "."));

@@ -160,3 +167,3 @@ }

function applyInstruction(moduleContext, stack, instruction) {
// Return was called, skip everything
// Return was called or a type error has occured, skip everything
if (stack === false || stack.return) {

@@ -167,3 +174,3 @@ return stack;

if (instruction.type !== "Instr" && instruction.type !== "LoopInstruction" && instruction.type !== "CallInstruction" && instruction.type !== "BlockInstruction" && instruction.type !== "IfInstruction") {
if ((0, _ast.isInstruction)(instruction) === false) {
return stack;

@@ -181,2 +188,6 @@ } // Recursively evaluate all nested instructions

if (instruction.intrs) {
stack = instruction.intrs.reduce(applyInstruction.bind(null, moduleContext), stack);
}
var type = (0, _getType.default)(moduleContext, stack, instruction);

@@ -263,5 +274,2 @@

stack = _toConsumableArray(stack).concat(_toConsumableArray(stackConsequent));
} else if (instruction.id === "return") {
stack.return = true;
return stack;
} else {

@@ -268,0 +276,0 @@ var _actual;

@@ -88,3 +88,3 @@ "use strict";

if (!moduleContext.isMutableGlobal(_index)) {
error = "Global ".concat(_index, " is immutable");
error = "global is immutable";
break;

@@ -301,4 +301,4 @@ }

case "shr_s":
case "rot_l":
case "rot_r":
case "rotl":
case "rotr":
{

@@ -488,10 +488,21 @@ args = [instruction.object, instruction.object];

/**
* Unreachable code
* return
*/
case "return":
{
args = moduleContext.return;
result = [_types.POLYMORPHIC];
stack.return = true;
break;
}
/**
* unreachable, trap
*/
case "unreachable":
case "trap":
case "return":
{
// Theres probably a nicer way to do this, but return is currently handled in `applyInstruction` directly
// TODO: These should be polymorphic
args = [];

@@ -541,2 +552,36 @@ result = [];

/**
* br_table
*/
case "br_table":
{
// TODO: Read all labels not just one
var _index7 = instruction.args[0].value;
if (!moduleContext.hasLabel(_index7)) {
error = "Module does not have memory ".concat(_index7);
break;
}
args = _toConsumableArray(moduleContext.getLabel(_index7)).concat(["i32"]);
break;
}
/**
* call_indirect
*/
case "call_indirect":
{
// TODO: There are more things to be checked here
args = _toConsumableArray(instruction.signature.params.map(function (p) {
return p.valtype;
})).concat(["i32"]);
result = instruction.signature.results.map(function (p) {
return p.valtype;
});
break;
}
/**
* Skip type checking

@@ -543,0 +588,0 @@ */

@@ -32,2 +32,3 @@ "use strict";

this.labels = [];
this.return = [];
this.debugName = "unknown";

@@ -46,2 +47,3 @@ }

this.labels = [expectedResult];
this.return = expectedResult;
this.debugName = debugName;

@@ -56,4 +58,6 @@ }

value: function addFunction(_ref) {
var args = _ref.params,
result = _ref.results;
var _ref$params = _ref.params,
args = _ref$params === void 0 ? [] : _ref$params,
_ref$results = _ref.results,
result = _ref$results === void 0 ? [] : _ref$results;
args = args.map(function (arg) {

@@ -60,0 +64,0 @@ return arg.valtype;

{
"name": "@webassemblyjs/validation",
"version": "1.5.1",
"version": "1.5.2",
"description": "Module AST validations",

@@ -19,11 +19,11 @@ "main": "lib/index.js",

"dependencies": {
"@webassemblyjs/ast": "1.5.1",
"@webassemblyjs/ast": "1.5.2",
"debug": "3.0.1"
},
"devDependencies": {
"@webassemblyjs/helper-test-framework": "1.5.1",
"@webassemblyjs/wasm-parser": "1.5.1",
"@webassemblyjs/wast-parser": "1.5.1",
"@webassemblyjs/helper-test-framework": "1.5.2",
"@webassemblyjs/wasm-parser": "1.5.2",
"@webassemblyjs/wast-parser": "1.5.2",
"wabt": "^1.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc