Merge pull request #197 from paritytech/fix-peek

Fix peek size on edge case
This commit is contained in:
Nikolay Volf
2018-03-08 06:00:56 +03:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

Binary file not shown.

View File

@@ -342,7 +342,10 @@ pub fn peek_size(source: &[u8]) -> usize {
if section_id <= 11 && section_len > 0 {
let next_cursor = cursor + new_cursor + section_len as usize;
if next_cursor >= source.len() {
if next_cursor > source.len() {
break;
} else if next_cursor == source.len() {
cursor = next_cursor;
break;
}
cursor = next_cursor;
@@ -498,6 +501,16 @@ mod integration_tests {
assert_eq!(peek_size(&buf), buf.len() - 9);
}
#[test]
fn peek_3() {
use super::peek_size;
let module = deserialize_file("./res/cases/v1/peek_sample.wasm").expect("Should be deserialized");
let buf = serialize(module).expect("serialization to succeed");
assert_eq!(peek_size(&buf), buf.len());
}
#[test]
fn module_default_round_trip() {
let module1 = Module::default();