http2: returns error in case of index 0

As is documented in RFC 7541, section 6.1
The index value of 0 is not used.  It MUST be treated as a decoding
error if found in an indexed header field representation.
pull/5386/head
Philippe Antoine 5 years ago committed by Victor Julien
parent 9788b2ec8d
commit e3b28bcf2a

@ -285,7 +285,14 @@ fn http2_frame_header_static(
});
} else {
//use dynamic table
if dyn_headers.len() + HTTP2_STATIC_HEADERS_NUMBER < n as usize {
if n == 0 {
return Some(HTTP2FrameHeaderBlock {
name: Vec::new(),
value: Vec::new(),
error: HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeIndex0,
sizeupdate: 0,
});
} else if dyn_headers.len() + HTTP2_STATIC_HEADERS_NUMBER < n as usize {
return Some(HTTP2FrameHeaderBlock {
name: Vec::new(),
value: Vec::new(),
@ -313,6 +320,7 @@ pub enum HTTP2HeaderDecodeStatus {
HTTP2HeaderDecodeError = 0x80,
HTTP2HeaderDecodeNotIndexed = 0x81,
HTTP2HeaderDecodeIntegerOverflow = 0x82,
HTTP2HeaderDecodeIndex0 = 0x83,
}
impl fmt::Display for HTTP2HeaderDecodeStatus {
@ -949,6 +957,21 @@ mod tests {
panic!("Result should not be an error: {:?}.", err);
}
}
let buf4: &[u8] = &[0x80];
let r4 = http2_parse_headers_block(buf4, &mut dynh);
match r4 {
Ok((remainder, hd)) => {
assert_eq!(hd.error, HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeIndex0);
assert_eq!(remainder.len(), 0);
assert_eq!(dynh.len(), 2);
}
Err(Err::Incomplete(_)) => {
panic!("Result should not have been incomplete.");
}
Err(Err::Error(err)) | Err(Err::Failure(err)) => {
panic!("Result should not be an error: {:?}.", err);
}
}
let buf2: &[u8] = &[
0x04, 0x94, 0x62, 0x43, 0x91, 0x8a, 0x47, 0x55, 0xa3, 0xa1, 0x89, 0xd3, 0x4d, 0x0c,
0x1a, 0xa9, 0x0b, 0xe5, 0x79, 0xd3, 0x4d, 0x1f,

Loading…
Cancel
Save