Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Fix decoding unterminated varint #134

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include = ["src/**/*", "Cargo.toml"]
bytes = "0.4"
protobuf = "= 2.15.1"
byteorder = "1.3.4"
integer-encoding = "1.1.5"
integer-encoding = { git = "https://github.com/yihuang/integer-encoding-rs.git", branch = "issue9" }
log = "0.4.8"
env_logger = "0.7.1"
tokio = { version = "0.1", default-features = false, features = ["codec", "io", "tcp", "rt-full"] }
Expand Down
5 changes: 3 additions & 2 deletions src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error;

use bytes::{BufMut, BytesMut};
use integer_encoding::VarInt;
use protobuf::Message;
use protobuf::{error::WireError, Message, ProtobufError};
use tokio::codec::{Decoder, Encoder};

use crate::messages::abci::*;
Expand All @@ -25,7 +25,8 @@ impl Decoder for ABCICodec {
if length == 0 {
return Ok(None);
}
let varint: (i64, usize) = i64::decode_var(&buf[..]);
let varint: (i64, usize) =
i64::decode_var(&buf[..]).ok_or(ProtobufError::WireError(WireError::UnexpectedEof))?;
if varint.0 as usize + varint.1 > length {
return Ok(None);
}
Expand Down