Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piper/convert malformed module error to be exception based #15

Conversation

pipermerriam
Copy link
Member

Builds on #14

What was wrong?

The invalid module error was magic string based.

How was it fixed?

Converted all invalid module errors to be exception based.

Cute Animal Picture

surprised_animals_34

Copy link
Contributor

@carver carver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at some point we ought to make the exception messages more meaningful. Not in this PR. 👍

wasm/__init__.py Outdated
len(F) > 1024
): # TODO: this is not part of spec, but this is required to pass tests. Tests pass with limit 10000, maybe more
return "exhaustion"
if (len(F) > 1024):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outer parens seem unnecessary

return store, "error", e.args[0]
except Exception as err:
if err.args[0] in {"trap", "exhaustion", "invalid", "malformed"}:
raise Exception("Invariant: these exceptions should no longer be using the base exception class") from err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

wasm/__init__.py Outdated
externtypestar, extertypeprimestar = ret
importstar = module["imports"]
if len(importstar) != len(externtypestar):
return "error: wrong import length"
raise InvalidModule("invalid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost a bit of info here: "wrong import length" could be the message for the InvalidModule message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, though funny enough, this code path isn't currently being excercised at all.

@@ -62,13 +62,8 @@ def instantiate_module_from_wasm_file(
wasmbytes = memoryview(wasm_module_file.read())
module = wasm.decode_module(wasmbytes)

if module == "malformed":
raise MalformedModule(f"Malformed wasm module: {file_path.name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including the file path that failed would probably be valuable, and the internal malformed exceptions don't have that. It might be worth catching and re-raising MalformedModule with that info.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#16

# validate
ret = wasm.validate_module(module)
if type(ret) == str and ret[:14] == "error: invalid":
raise InvalidModule(f"Invalid wasm module: {file_path.name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (could re-raise with the file name)

@pipermerriam pipermerriam merged commit 2179122 into ethereum:master Jan 16, 2019
@pipermerriam pipermerriam deleted the piper/convert-malformed-module-error-to-be-exception-based branch January 16, 2019 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants