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

feat(interface-types) Greatly improve errors #1285

Merged
merged 7 commits into from
Mar 12, 2020

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Mar 10, 2020

This PR is build on top of #1284. It must be merged first. View the exact diff.

Errors in wasmer-interface-types were just &'static str, which isn't quite great 😉. This PR introduces the errors module, with structures that represent errors. A Display implementation maps the errors to strings.

Hywan added a commit to Hywan/wasmer that referenced this pull request Mar 10, 2020
@Hywan
Copy link
Contributor Author

Hywan commented Mar 10, 2020

bors try

bors bot added a commit that referenced this pull request Mar 10, 2020
@bors
Copy link
Contributor

bors bot commented Mar 10, 2020

try

Build succeeded

@Hywan Hywan marked this pull request as ready for review March 10, 2020 16:48
Hywan added 3 commits March 10, 2020 17:49
The new `errors` module contains structure to represent errors,
instead of using basic strings. The first usage is in the interpreter
itself.
@Hywan Hywan force-pushed the feat-interface-types-better-error branch from 04bf6d2 to 4ffb158 Compare March 10, 2020 16:49
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good to me other than my comments!

lib/interface-types/src/errors.rs Show resolved Hide resolved
"`{}` failed because there is not enough data on the stack (needs 2).",
instruction_name,
))
if memory_view.len() < pointer + length {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may be affected by the same bug I recently fixed in WasmPtr,

Given a String, "hi" at address 0xFFFE the memory looks like

0xFFFE: 'h'
0xFFFF: 'i'

ptr (0xFFFE) + len (2) = 0x10000, failing this bounds check. The fix, in general, is annoying when you handle length = 0 and zero sized types.

See #1272 for my fix.

Better to have false positives than false negatives in bounds-checking code, but leaving a comment here as a heads up. It might make sense to do a full pass for these types of bugs and fix them in a separate PR if you think it might clutter this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify more, we want to make sure out of bounds pointers are never derefed, so ptr = 0x10000 and length = 0 will not be caught by the naive solution of changing < to <= here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand. I've pushed a new commit to use inclusive an range, and consequently a special condition to handle empty string, but I'm not sure there is a bug right now. The test_memory_to_string already reads at bounds.

lib/interface-types/src/interpreter/mod.rs Outdated Show resolved Hide resolved
@Hywan
Copy link
Contributor Author

Hywan commented Mar 12, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 12, 2020

@bors bors bot merged commit f77df9b into wasmerio:master Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Do you like to read? 🎉 enhancement New feature! 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants