Skip to content

Commit

Permalink
Merge pull request #79 from kralverde/more_packet_hardening
Browse files Browse the repository at this point in the history
Buffer check for varint decoding
  • Loading branch information
Snowiiii authored Sep 7, 2024
2 parents ca2e4e2 + e4106c3 commit cd25387
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ impl VarInt {
pub fn decode_partial(r: &mut &[u8]) -> Result<i32, VarIntDecodeError> {
let mut val = 0;
for i in 0..Self::MAX_SIZE {
if !r.has_remaining() {
return Err(VarIntDecodeError::Incomplete);
}
let byte = r.get_u8();
val |= (i32::from(byte) & 0b01111111) << (i * 7);
if byte & 0b10000000 == 0 {
Expand Down Expand Up @@ -71,6 +74,9 @@ impl VarInt {
pub fn decode(r: &mut &[u8]) -> Result<Self, VarIntDecodeError> {
let mut val = 0;
for i in 0..Self::MAX_SIZE {
if !r.has_remaining() {
return Err(VarIntDecodeError::Incomplete);
}
let byte = r.get_u8();
val |= (i32::from(byte) & 0b01111111) << (i * 7);
if byte & 0b10000000 == 0 {
Expand Down

0 comments on commit cd25387

Please sign in to comment.