Skip to content

Commit

Permalink
Merge pull request #319 from rpgp/fix-alloc
Browse files Browse the repository at this point in the history
fix(packet-parser): increase buffer size for unknown size
  • Loading branch information
dignifiedquire committed Mar 23, 2024
2 parents a3dd485 + 1013c13 commit 03fb265
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/packet/many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,16 @@ impl<R: Read> Iterator for PacketParser<R> {
}

// if the parser returned `Incomplete`, and it needs more data than the buffer can hold, we grow the buffer.
if let Some(Needed::Size(sz)) = needed {
if b.usable_space() < sz.into() && self.capacity * 2 < MAX_CAPACITY {
self.capacity *= 2;
let capacity = self.capacity;
if let Some(needed) = needed {
let requested_size: usize = match needed {
Needed::Size(sz) => sz.into(),
Needed::Unknown => 1024,
};

if b.usable_space() < requested_size {
self.capacity = std::cmp::min(self.capacity * 2, MAX_CAPACITY);
b.make_room();
b.reserve(capacity);
b.reserve(self.capacity);
}
}
}
Expand Down

0 comments on commit 03fb265

Please sign in to comment.