Skip to content

Commit

Permalink
Rewrite ProtobufReader to properly handle out-of-order and missing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerkindt committed Sep 13, 2021
1 parent 6af109b commit 681ff2b
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 192 deletions.
7 changes: 3 additions & 4 deletions src/io/protobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub trait ProtoWrite {
}

fn write_tagged_bytes(&mut self, field: u32, value: &[u8]) -> Result<(), Error> {
self.write_tag(field, Format::VarInt)?;
self.write_tag(field, Format::LengthDelimited)?;
self.write_bytes(value)
}

Expand Down Expand Up @@ -299,9 +299,8 @@ impl<R: Read> ProtoRead for R {
}

fn read_bytes(&mut self) -> Result<Vec<u8>, Error> {
let len = self.read_varint()? as usize;
let mut vec = vec![0_u8; len];
self.read_exact(&mut vec[..])?;
let mut vec = Vec::new();
self.read_to_end(&mut vec)?;
Ok(vec)
}

Expand Down
Loading

0 comments on commit 681ff2b

Please sign in to comment.