Skip to content

Commit

Permalink
fix: panic on invalid dynamic size message
Browse files Browse the repository at this point in the history
  • Loading branch information
sno2 committed Sep 15, 2023
1 parent e833eca commit d669282
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl<'a> Decoder<'a> {
},
FieldRepresentation::SizeUpdate => {
// Handle the dynamic table size update...
self.update_max_dynamic_size(buffer_leftover)
self.update_max_dynamic_size(buffer_leftover)?
}
};

Expand Down Expand Up @@ -445,19 +445,16 @@ impl<'a> Decoder<'a> {
/// size of the underlying dynamic table, possibly causing a number of
/// headers to be evicted from it.
///
/// Assumes that the first byte in the given buffer `buf` is the first
/// octet in the `SizeUpdate` block.
///
/// Returns the number of octets consumed from the given buffer.
fn update_max_dynamic_size(&mut self, buf: &[u8]) -> usize {
let (new_size, consumed) = decode_integer(buf, 5).ok().unwrap();
fn update_max_dynamic_size(&mut self, buf: &[u8]) -> Result<usize, DecoderError> {
let (new_size, consumed) = decode_integer(buf, 5)?;
self.header_table.dynamic_table.set_max_table_size(new_size);

info!("Decoder changed max table size from {} to {}",
self.header_table.dynamic_table.get_size(),
new_size);

consumed
Ok(consumed)
}
}

Expand Down Expand Up @@ -1351,6 +1348,13 @@ mod tests {
_ => false,
});
}

#[test]
fn test_invalid_dynamic_size_update() {
let mut decoder = Decoder::new();
let hex_dump = &[0x3f];
let _ = decoder.decode(hex_dump);
}
}

/// The module defines interop tests between this HPACK decoder
Expand Down

0 comments on commit d669282

Please sign in to comment.