From 5c72713e2a1c5105d7e923246a4a2e54a5622c6b Mon Sep 17 00:00:00 2001 From: Anthony Ramine <123095+nox@users.noreply.github.com> Date: Thu, 6 May 2021 15:26:01 +0200 Subject: [PATCH] Remove panic (fixes #395) (#541) I don't even understand why that should panic, what's wrong with values greater than 0x0fff_ffff? If we truly wish to avoid very large dynamic tables, we should do so when we get the large SETTINGS_HEADER_TABLE_SIZE value, not when encoding it. --- src/hpack/encoder.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hpack/encoder.rs b/src/hpack/encoder.rs index cafd405..15a1175 100644 --- a/src/hpack/encoder.rs +++ b/src/hpack/encoder.rs @@ -384,10 +384,6 @@ fn encode_int( value -= low; - if value > 0x0fff_ffff { - panic!("value out of range"); - } - dst.put_u8(first_byte | low as u8); rem -= 1; @@ -851,6 +847,20 @@ mod test { assert_eq!("sup", huff_decode(&dst[9..])); } + #[test] + fn test_large_size_update() { + let mut encoder = Encoder::default(); + + encoder.update_max_size(1912930560); + assert_eq!(Some(SizeUpdate::One(1912930560)), encoder.size_update); + + let mut dst = BytesMut::with_capacity(6); + encoder + .encode_size_updates(&mut (&mut dst).limit(6)) + .unwrap(); + assert_eq!([63, 225, 129, 148, 144, 7], &dst[..]); + } + #[test] #[ignore] fn test_evicted_overflow() {