829 Commits

Author SHA1 Message Date
NikVolf
a0c3f27b32 export builders doc effort 2018-01-09 12:53:20 +03:00
NikVolf
6d55afe3ee data builder doc effort 2018-01-09 12:40:04 +03:00
NikVolf
b24ca8ee2d rearrange exports 2018-01-09 12:37:19 +03:00
NikVolf
9e037b88aa more code doc effort 2018-01-09 12:36:21 +03:00
NikVolf
07e3fc47b3 code builder doc effort 2018-01-09 12:29:08 +03:00
NikVolf
b26da22e89 expose builders 2018-01-09 12:23:42 +03:00
Sergey Pepyakin
185dbd3b1b
Merge pull request #133 from emk/impl_error
Implement `Error` for error types
2018-01-03 17:34:04 +03:00
Eric Kidd
a1888a5f1f
Fix typos in error messages 2018-01-02 08:17:37 -05:00
Eric Kidd
7fdf6a8bec Fix debug_assert build problem in release mode
Because `debug_assert_eq!` is implemented using `if
cfg!(debug_assertions)`, we need to avoid referring to `slow_len` unless
it is actually being included in the build.
2018-01-01 15:33:05 -05:00
Eric Kidd
e7d13ed7d1 Don't allow deserializing names which shouldn't exist
This addresses the potential security issue discussed in the last patch
by implementing custom versions of `deserialize` that check for objects
corresponding to each name.
2018-01-01 15:23:06 -05:00
Eric Kidd
e01c0ef043 Implement Error for error types
This makes it easier to handle errors from parity-wasm in an idiomatic
fashion.

Fixes #125.
2018-01-01 09:43:56 -05:00
Eric Kidd
53d7c8ef3a Implement name section parsing
Spec: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section
Issue: https://github.com/paritytech/parity-wasm#129

This is a basic implementation of *.wasm name sections, including
serialization and deserialization. As per the discussion with @NikVolf
on #129, we implement a custom `IndexMap` type.

Before merging this, we should consider the following issues:

- [ ] SECURITY: The custom `IndexMap` structure is exposed to a denial
  of service attack. This can be easily prevented; see below for discussion.
- [ ] We probably want top-level `mod.module_name_section()`,
  `mod.function_name_section()` and `mod.local_name_section()` APIs to
  make it easy to access the relevant sections. Only one of each section
  is allowed, so this would make semantic sense.
- [ ] We need a real-world *.wasm file with a module and local name sections.
- [ ] It looks like name sections will normally be left unparsed. But we
  should probably go ahead and hook them up to the fuzzer manually.
- [ ] We currently require all entries in an `IndexMap` to be in
  ascending order, as required by the standard. We could relax this
  check if we needed to handle non-compliant files.

Security and `IndexMap`:

It's possible to create a local name section containing three entries,
for the indices `u32::MAX-2`, `u32::MAX-1` and `u32::MAX`, each of
which contains an entry for a local variable with index `u32::MAX`. This
will consume an utterly ridiculous amount of RAM.

There are three possible fixes, all of which are relatively easy:

1. Switch from `IndexMap<T>` to `BTreeMap<u32, T>`.
2. Keep the index `IndexMap<T>` API, but reimplement it using a private
   `BTreeMap<u32, T>`. This allows us to replace the implementation
   later without breaking the API.
3. Keep `IndexMap<T>`, but refuse to deserialize maps containing too
   many gaps. This would require a slightly different `Deserialize` API,
   particular to deal with `IndexMap<IndexMap<String>>`.
2017-12-31 09:57:34 -05:00
NikVolf
42321afa39 bump version 2017-12-28 12:02:38 +03:00
Nikolay Volf
e07700012c
Merge pull request #131 from paritytech/serialize-buf
Deserialize buffer takes slice
2017-12-28 12:02:14 +03:00
NikVolf
96c89eb1d6 fix dependency spec 2017-12-27 16:00:52 +03:00
NikVolf
97257a7865 serialize buffer takes slice 2017-12-27 12:28:42 +03:00
NikVolf
138e35da3b bump version 2017-12-27 12:06:17 +03:00
Nikolay Volf
d5b1547707
Merge pull request #130 from paritytech/mut-str
Fix API for import entry
2017-12-27 12:05:33 +03:00
NikVolf
bb21e9d208 fix api for import entry 2017-12-26 19:08:28 +03:00
Nikolay Volf
9895133048
Merge pull request #124 from paritytech/extract-validation
Extract validation
2017-12-05 20:07:20 +01:00
Sergey Pepyakin
f6891e6de9 clean func 2017-12-05 19:57:07 +01:00
Sergey Pepyakin
7c7e3bd051 use self::Opcode::* 2017-12-05 19:45:06 +01:00
Sergey Pepyakin
dea1f3cac0 Oops 2017-12-05 19:44:40 +01:00
Sergey Pepyakin
3b86a8e335 Fix break condition. 2017-12-05 19:34:38 +01:00
Sergey Pepyakin
7ad604b5ad ok_or_else fixes 2017-12-05 19:32:26 +01:00
Sergey Pepyakin
bef4a644fd Fix braces 2017-12-05 18:56:17 +01:00
Sergey Pepyakin
8bd984b10f Fix imports 2017-12-05 18:54:28 +01:00
Sergey Pepyakin
15b93038f9 Fix matches 2017-12-05 18:54:23 +01:00
Sergey Pepyakin
9c442f6be1 Fixes 2017-12-05 18:12:10 +01:00
Sergey Pepyakin
93b61bc2dc Old test uncommented 2017-12-05 17:43:17 +01:00
Sergey Pepyakin
e9ec5e8aa8 Clean 2017-12-05 17:25:32 +01:00
Sergey Pepyakin
42142f6513 Clean 2017-12-05 17:10:40 +01:00
Sergey Pepyakin
ba6018957a Refactor limits test 2017-12-05 17:06:39 +01:00
Sergey Pepyakin
b146c21147 validate element section 2017-12-05 16:51:26 +01:00
Sergey Pepyakin
d30e4052cb Add data section validation 2017-12-05 16:41:16 +01:00
Sergey Pepyakin
74f4c7c49a Emit Opcode::End for init exprs 2017-12-05 16:31:07 +01:00
Sergey Pepyakin
e41e0f98ef Refactor 2017-12-05 14:11:00 +01:00
Sergey Pepyakin
11e4cd6ba1 Import section validation 2017-12-05 12:57:42 +01:00
Sergey Pepyakin
056ac258cd Test recursive calls 2017-12-05 12:41:14 +01:00
Sergey Pepyakin
71b8b933bf Clean 2017-12-05 12:26:42 +01:00
Sergey Pepyakin
8afb7b6450 Add checks for tables and memories count. 2017-12-05 12:12:54 +01:00
Sergey Pepyakin
991fb8fcd8 Clean 2017-12-05 12:07:39 +01:00
Sergey Pepyakin
b20eaec695 Make require_function[_type] to return slice 2017-12-05 12:06:41 +01:00
Sergey Pepyakin
ad3f882274 Validate globals 2017-12-05 12:03:06 +01:00
Sergey Pepyakin
4984eca6d6 Clean 2017-12-05 11:39:51 +01:00
Sergey Pepyakin
71c9709885 get_global can only use imported globals. 2017-12-04 18:00:51 +01:00
Sergey Pepyakin
251d4d68db Validate start_section 2017-12-04 17:36:48 +01:00
Sergey Pepyakin
7ea00b975b Fix tests. 2017-12-01 20:27:33 +03:00
Sergey Pepyakin
29613aef9c Use new validation. 2017-12-01 20:08:42 +03:00
Sergey Pepyakin
5b921b6cf9 Reimpl vanilla validator 2017-12-01 20:06:43 +03:00