Skip to content

Commit 9679a32

Browse files
leoyvensJannis Pohlmann
authored andcommitted
runtime: Fix TypeArray deserialization
AS has changed `byteLength` to actually be the byte length.
1 parent ef86214 commit 9679a32

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

runtime/wasm/src/asc_abi/class.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ pub(crate) struct TypedArray<T> {
113113
pub buffer: AscPtr<ArrayBuffer<T>>,
114114
/// Byte position in `buffer` of the array start.
115115
byte_offset: u32,
116-
/// Byte position in `buffer` of the array end, which is 1 byte past the
117-
/// last byte of the payload. Called `byteLength` in Asc.
118-
end_byte: u32,
116+
byte_length: u32,
119117
}
120118

121119
impl<T: AscValue> TypedArray<T> {
@@ -124,15 +122,14 @@ impl<T: AscValue> TypedArray<T> {
124122
TypedArray {
125123
buffer: AscPtr::alloc_obj(&buffer, heap),
126124
byte_offset: 0,
127-
end_byte: buffer.byte_length,
125+
byte_length: buffer.byte_length,
128126
}
129127
}
130128

131129
pub(crate) fn to_vec<H: AscHeap>(&self, heap: &H) -> Vec<T> {
132-
self.buffer.read_ptr(heap).get(
133-
self.byte_offset,
134-
(self.end_byte - self.byte_offset) / size_of::<T>() as u32,
135-
)
130+
self.buffer
131+
.read_ptr(heap)
132+
.get(self.byte_offset, self.byte_length / size_of::<T>() as u32)
136133
}
137134
}
138135

runtime/wasm/src/module/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ops::Deref;
44
use wasmi::{
55
nan_preserving_float::F64, Error, Externals, FuncInstance, FuncRef, HostError, ImportsBuilder,
66
MemoryRef, Module, ModuleImportResolver, ModuleInstance, ModuleRef, NopExternals, RuntimeArgs,
7-
RuntimeValue, Signature, Trap, ValueType,
7+
RuntimeValue, Signature, Trap,
88
};
99

1010
use graph::components::ethereum::*;
@@ -599,10 +599,7 @@ pub struct EnvModuleResolver;
599599
impl ModuleImportResolver for EnvModuleResolver {
600600
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
601601
Ok(match field_name {
602-
"abort" => FuncInstance::alloc_host(
603-
signature.clone(),
604-
ABORT_FUNC_INDEX,
605-
),
602+
"abort" => FuncInstance::alloc_host(signature.clone(), ABORT_FUNC_INDEX),
606603
_ => {
607604
return Err(Error::Instantiation(format!(
608605
"Export '{}' not found",

runtime/wasm/src/module/test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ extern crate ipfs_api;
33
extern crate parity_wasm;
44

55
use self::graph_mock::FakeStore;
6-
use ethabi::{LogParam, Token};
6+
use ethabi::Token;
77
use failure::Error;
88
use futures::sync::mpsc::{channel, Sender};
99
use graph::components::ethereum::*;
1010
use graph::components::store::*;
11-
use graph::components::subgraph::*;
1211
use graph::data::store::scalar;
1312
use graph::data::subgraph::*;
14-
use graph::util;
15-
use graph::web3::types::{Bytes, *};
13+
use graph::web3::types::*;
1614
use hex;
17-
use std::collections::HashMap;
1815
use std::io::Cursor;
19-
use std::iter::FromIterator;
2016
use std::str::FromStr;
2117

2218
use super::*;

0 commit comments

Comments
 (0)