Skip to content

Commit

Permalink
fix reading version bytes on version mismatch error (fix #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jun 12, 2020
1 parent 6b0f242 commit 655e0c0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions wain-syntax-binary/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ impl<'s> Parse<'s> for Module<'s> {
match parser.input {
[0x01, 0x00, 0x00, 0x00, ..] => parser.eat(4),
_ => {
return Err(
parser.error(ErrorKind::VersionMismatch(parser.input.try_into().unwrap()))
)
let bytes = parser.input[..4].try_into().unwrap();
return Err(parser.error(ErrorKind::VersionMismatch(bytes)));
}
}

Expand Down Expand Up @@ -1153,4 +1152,15 @@ mod tests {
let mut parser = Parser::new(&bin);
let _: Root<'_, _> = unwrap(parser.parse());
}

#[test]
fn regression_issue_29() {
// .asm.19.asm.195.
let bin: &[_] = b"\x00\x61\x73\x6d\x01\x31\x39\x00\x61\x73\x6d\x01\x31\x39\x35\x01";
let mut parser = Parser::new(bin);
match parser.parse::<Module<'_>>() {
Ok(_) => panic!("unexpected success"),
Err(err) => assert!(matches!(err.kind, ErrorKind::VersionMismatch(_))),
}
}
}

0 comments on commit 655e0c0

Please sign in to comment.